Regular expression commonly used 18 kinds of

Source: Internet
Author: User

1. Pure Digital Detection: public string A = "^[0-9]+$";

2.11-digit mobile number (1): public string B = "^1\d{10}$";

3. Digital or English: public string C = "^[a-za-z0-9]+$";

4. Pure Chinese characters: public string D = "^[\u4e00-\u9fa5]+$";

5. Identity card:
Identity card Regular expression (15-bit)
public string E1 = "/^[1-9]\d{7} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3}$/";
Identity card Regular expression (18-bit)
public string E2 = "/^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{4}$/";

6. Verify e-mail format: string f= "\\w{1,}@\\w{1,}\\.\\w{1,}";

7. Determine the date and time,
1.2009-1-2/12:01
2.12-1/13:05
3.15:52
Support for 3 format judgments: String g= "(\d{4}-) * ([01]*\d-[0-3]*\d\/) *[0-2]*\d:[0-5]*\d";

8. Verify that the password consists of a special alphanumeric underline that is not less than 6 digits or less than 15 digits
String H= "^. {6,15}___fckpd___0quot;;/ /Limit the beginning, must start from the first match, limit the end, the total number of digits must not exceed 15 bits, otherwise even greater than 15 bits can still be verified through
System.Text.RegularExpressions.Regex regpwd = new System.Text.RegularExpressions.Regex (H, Options);
string pwd = Txtpwd.text;
if (Regpwd.ismatch (PWD))
{Yes}else{no};

9. Verify the user name: only 1-30 strings beginning with a letter can be entered
function Istruename (s)
{
var patrn=/^[a-za-z]{1,30}$/;
if (!patrn.exec (s)) return false
return True
}

10. Check Password: Only 6-20 letters, numbers, underscores can be entered
function ispasswd (s)
{
var patrn=/^ (\w) {6,20}$/;
if (!patrn.exec (s)) return false
return True
}

11. Check the ordinary telephone, fax number: Can "+" start, in addition to the number, can contain "-"
function Istel (s)
{
var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? (\d) {1,12}) +$/;
var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +$/;
if (!patrn.exec (s)) return false
return True
}

12. Check the mobile phone number: Must start with a number, in addition to the number, can contain "-"
function Ismobil (s)
{
var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +$/;
if (!patrn.exec (s)) return false
return True
}

13. Verifying the ZIP code
function Ispostalcode (s)
{
var patrn=/^[a-za-z0-9]{3,12}$/;
var patrn=/^[a-za-z0-9]{3,12}$/;
if (!patrn.exec (s)) return false
return True
}

14. Verifying Search Keywords
function Issearch (s)
{
var patrn=/^[^ ' [email protected]#$%^&* () +=|\\\][\]\{\}:;\ ' \,.<>/?] {1} [^ ' [email protected]$%^& () +=|\\\] [\]\{\}:;\ ' \,.<>?] {0,19}$/;
if (!patrn.exec (s)) return false
return True
}

function IsIP (s)//by zergling
{
var patrn=/^[0-9.] {1,20}$/;
if (!patrn.exec (s)) return false
return True

15. Verifying the Mailbox
function Isemail (s)
{
var patrn=/^[a-za-z0-9_\-]{1,}@[a-za-z0-9_\-]{1,}\. [a-za-z0-9_\-.] {1,}$/;
if (!patrn.exec (s)) return false
return True
}

16. Check the date
function IsDate (s)
{
var patrn=/^ ((\d{2} ([[02468][048]) | ( [13579] [26])) [\-\/\s]? (((0? [13578]) | (1[02])) [\-\/\s]? ((0? [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\-\/\s]? ((0? [1-9]) | ([1-2][0-9]) | (30))) | (0?2[\-\/\s]? ((0? [1-9]) | ([1-2][0-9])))) | (\d{2} ([02468][1235679]) | ( [13579] [01345789])) [\-\/\s]? (((0? [13578]) | (1[02])) [\-\/\s]? ((0? [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\-\/\s]? ((0? [1-9]) | ([1-2][0-9]) | (30))) | (0?2[\-\/\s]? ((0? [1-9]) | (1[0-9]) | (2[0-8]))))) (\s ((0?[ 0-9]) | ([1-2][0-3])) \:([0-5]? [0-9]) ((\s) | (\:([0-5]? [0-9])))? $/;
if (!patrn.exec (s)) return false
return True
}

17. Verifying Currency format
function Iscurrency (s)
{
var patrn=/^\d+ (\.\d+)? $/;
if (!patrn.exec (s)) return false
return True
}

Regular expression commonly used 18 kinds of

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.