Sample Code for JavaScript Form Verification Using Regular Expressions

Source: Internet
Author: User

Javascript Form Verification Regular Expressions
Use a regular expression to determine whether it is a 0-9 Arabic number CopyCode The Code is as follows: function regisdigit (fdata)
{
VaR Reg = new Regexp ("^ [0-9] $ ");
Return (Reg. Test (fdata ));
}

Use this expression to obtain the string length.Copy codeThe Code is as follows: function regdatalength (fdata)
{
VaR vallength = fdata. length;
VaR Reg = new Regexp ("^ [\ u0391-\ uffe5] $ ");
VaR result = 0;
For (I = 0; I <vallength; I ++)
{
If (Reg. Test (fdata. charat (I )))
{
Result + = 2;
}
Else
{
Result ++;
}
}
Return result;
}

Application expansion determines whether it is a valueCopy codeThe Code is as follows: function regisnumber (fdata)
{
VaR Reg = new Regexp ("^ [-]? [0-9] + [\.]? [0-9] + $ ");
Return Reg. Test (fdata)
}

Verify that email is correctCopy codeThe Code is as follows: function regisemail (fdata)
{
VaR Reg = new Regexp ("^ [0-9a-za-z] + @ [0-9a-za-z] + [\.] {1} [0-9a-za-z] + [\.]? [0-9a-za-z] + $ ");
Return Reg. Test (fdata );
}

Determine whether the mobile phone number is correctCopy codeThe Code is as follows: function regisphone (fdata)
{
VaR Reg =/^ (\ + 86 )? (1 [0-9] {10}) $ /;
Return Reg. Test (fdata );
}

Related Article

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.