Comparison of regular expressions and dates in JS

Source: Internet
Author: User
From: http://publishblog.blogchina.com/blog/tb. B? Diaryid = 5797645

// Check whether it is composed of digits

Code
Code:

Function isdigit (s)
{
VaR patrn =/^ [0-9] $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Check Logon Name: You can enter only 5-20 strings starting with a letter, which can contain numbers, "_", and ".".

Code
Code:

Function isregisterusername (s)
{
VaR patrn =/^ [A-Za-Z] ([a-zA-Z0-9] | [. _]) $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Check user name: only 1-30 strings starting with letters can be entered

Code
Code:

Function istruename (s)
{
VaR patrn =/^ [A-Za-Z] $ /;
If (! Patrn.exe C (s) return false
Return true
}
}}

// Password verification: only 6-20 letters, numbers, and underscores can be entered
Code:

Function ispasswd (s)
{
VaR patrn =/^ (\ W) $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Verify the phone number and fax number. The phone number can start with "+" and contain "-" in addition to numbers.

Code
Code:

Function istel (s)
{
// Var patrn =/^ [+] (\ D) []? ([-]? (\ D) + $ /;
VaR patrn =/^ [+] (\ D) []? ([-]? (\ D) | []) + $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Verify the mobile phone number. It must start with a number and can contain "-" in addition to a number.

Code
Code:

Function ismobil (s)
{
VaR patrn =/^ [+] (\ D) []? ([-]? (\ D) | []) + $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Verify the zip code

Code
Code:

Function ispostalcode (s)
{
// Var patrn =/^ [a-zA-Z0-9] $ /;
VaR patrn =/^ [a-zA-Z0-9] $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Verify the search keyword

Code
Code:

Function issearch (s)
{
VaR patrn =/^ [^ '~! @ # $ % ^ & * () + = | \] [\] \:; '\,. <>/?] [^ '~! @ $ % ^ & () + = | \]
[\] \:; '\,. <>?] $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function isip (s) // By zergling
{
VaR patrn =/^ [0-9.] $ /;
If (! Patrn.exe C (s) return false
Return true
}

*
......
[Read the full text]

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.