JavaScript example code for form validation using regular expressions--regular expressions

Source: Internet
Author: User
JavaScript Form Validation Regular expression encyclopedia
Using regular expressions to determine whether the Arabic numerals are 0-9
Copy Code code as follows:

function Regisdigit (fdata)
{
var reg = new RegExp ("^[0-9]$");
Return (Reg.test (fdata));
}

Use this expression to get the length of the string
Copy Code code 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;
}

Apply an extension to determine whether a value
Copy Code code as follows:

function Regisnumber (fdata)
{
var reg = new RegExp ("^[-]?[ 0-9]+[\.]? [0-9]+$ ");
Return Reg.test (Fdata)
}

Verify that the email is correct
Copy Code code 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 if the phone number is correct
Copy Code code 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.