JS Regular Reprint

Source: Internet
Author: User

Examples of regular expressions used in script, but without saying how these regular expressions are used, now give you a few examples that you can look at.
Use regular expressions to determine if the Arabic numerals are 0-9

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

Use this expression to get the length of the string

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 extension to determine if the value is numeric

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

Verify email is correct

function Regisemail (fData)
{
var reg = new RegExp ("^[0-9a-za-z][email protected][0-9a-za-z]+[\.") {1} [0-9a-za-z]+[\.]? [0-9a-za-z]+$ ");
Return Reg.test (FData);
}

Determine if the phone number is correct

function Regisphone (fData)
{
var reg =/^ (\+86)? (1[0-9]{10}) $/;
Return Reg.test (FData);
}

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.