Regular expression some usage table

Regular expressions require .test() when using jQuery

For example, in the code below, when a regular expression is used on a registration page to match the name, it needs to be in English or Chinese and cannot be a number

code

function sub() {
        userName = $('#userName').val();
        password = $('input[type="password"]')[0].value;
        password2 = $('input[type="password"]')[1].value;
        name = $('#6').val();
        var userName2 = / ^ [a-zA-Z] [a-zA-Z0-9 _] * $ /;
        var name2 = /^.{1,10}[^\d]+$/

        if (userName2.test(userName[0])) {

        }else{
            alert('The first letter must be a letter!');
            return
        }
        if (name2.test(name)) {

        }else {
            alert('Name 2 has 10 digits and no numbers are allowed')
            return
        }
        alert('Registration successful');
            setTimeout("location.href='http://www.baidu.com';",1000);
    }

 Digits: ^[0-9]*$
Digits of n digits: ^\d{n}$
Digits of at least n digits: ^\d{n,}$
Digits of mn digits: ^\d{m,n}$
Zero and non-zero leading numbers: ^(0|[1-9][0-9]*)$
Non-zero leading numbers with up to two decimal places: ^([1-9][0-9]* )+(.[0-9]{1,2})?$
A positive or negative number with 1-2 decimal places: ^(\-)?\d+(\.\d{1,2})?$
Positive, negative, and decimal numbers: ^(\-|\+)?\d+(\.\d+)?$

Chinese characters: ^[\u4e00-\u9fa5]{0,}$
English and numbers: ^[A-Za-z0-9]+$ or ^[A-Za-z0-9]{4,40}
$ All characters from 3-20: ^.{3,20}$
A string consisting of 26 English letters: ^[A-Za-z]+$ A
string consisting of 26 uppercase English letters: ^[AZ] +$
A string consisting of 26 lowercase English letters: ^[az]+$

Email address: ^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
Domain name: [a-zA-Z0 -9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
InternetURL: [a-zA-z]+://[^\s]* or ^http://([\w-]+\.)+[\w-]+(/[\w-./ ?%&=]*)?$
Mobile number: ^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18 [0|1|2|3|5|6|7|8|9])\d{8}$
PhoneNumber("XXX-XXXXXXX","XXXX-XXXXXXXX","XXX-XXXXXXX","XXX- XXXXXXXX", "XXXXXXX" and "XXXXXXXX): ^($$\d{3,4}-)|\d{3.4}-)?\d{7,8}$
Domestic phone numbers (0511-4405222, 021 -87888822):\d{3}-\d{8}|\d{4}-\d{7}
ID number (15 digits, 18 digits): ^\d{15}|\d{18 }$
Short ID number (number, letter x ending): ^([0-9]){7,18}(x|X)?$ or ^\d{8,18}|[0-9x]{ 8,18}|[0-9X]{8,18}?$ Is
the account number legal (begins with letters, allows 5-16 bytes, and allows alphanumeric underscores): ^[a-zA-Z][a-zA- Z0-9_]{4,15}$
Password (starting with a letter, length between 6~18, can only contain letters, numbers and underscores): ^[a-zA-Z]\w{5,17}$
Strong password (must contain a combination of uppercase and lowercase letters and numbers, no special characters, length between 8-10): ^(?=.*\d)(?=.*[az])(?=.* [AZ]).{8,10}$

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326623562&siteId=291194637