Universal check function for form text field

Source: Internet
Author: User
Name: General check function for form text field
Function: Detects all input text that must be non-null, such as name, account number, email address, etc.
The checksum is now only for text fields, and if you want to target other domain objects in the form, you can change the criteria for judgment.
How to: Add title text to the text field you want to detect. The text is in the prompt message, you want to prompt the user with the Chinese name of the field. For example, to detect user names
HTML follows <input name= "txt_1" title= "name", and, of course, it's best to edit the domain with visual tools such as Dreamweaver or something.
If you want to detect numeric types of data, then the domain ID unified to SZ.
JavaScript to determine the date type is more cumbersome, so there is no date-type validation program. The master can be added.
Oh.. Maybe it's more convenient to do it in VBScript.
Program to compare grass, just to provide a train of thought. Initiate :)
Oh, yes, function call method:< form onsubmit= "return Dovalidate ()" >
function Dovalidate ()
{
FM=DOCUMENT.FORMS[0]//Only detect a form, if multiple can change the condition of judgment
for (i=0;i<fm.length;i++)
{
Detection criteria, depending on the type can be modified
if (fm[i].tagname.touppercase () = = "INPUT" &&fm[i].type.touppercase () = = "TEXT" && (fm[i].title!= ""))

if (fm[i].value== "")//
{
Str_warn1=fm[i].title+ "cannot be empty!";
alert (STR_WARN1);
Fm[i].focus ();
return false;
}
if (fm[i].id.touppercase () = = "SZ")//Digital Checksum
{
if (isNaN (Fm[i].value))
{str_warn2=fm[i].title+ "wrong format";
alert (STR_WARN2);
Fm[i].focus ();
return false;
}
}
}
return true;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.