A regular expression is a logical formula for a string operation, which is a "rule string" that is used to express a filter logic for a string, using predefined specific characters and combinations of those specific characters.
The purpose of regular expressions
1. Whether the given string conforms to the filtering logic of the regular expression (called "match");
2. You can get the specific part we want from the string using a regular expression.
The regular expression is characterized by
1. Flexibility, logic and functionality are very strong;
2. Complex control of strings can be achieved quickly and in a very simple way;
3. For people who have just come into contact, it is more obscure and difficult to understand.
Registry validation
1. Get ID
function $ (ID) { return document.getElementById (ID);}
2. Verify your Name
function CheckName () { //Gets the value var username=$ (' user '). Value; The judgment cannot be null if (username== ') { $ (' s1 '). innerhtml= ' username cannot be empty '; return false; } The regular expression var reg=/^[a-za-z][a-za-z0-9]{4,9}$/; Detects if the input matches the regular expression if (!reg.test (username)) { $ (' s1 '). innerhtml= ' username must be a 5-10-digit number or letter consisting of a number at the beginning; return false; } Match, return empty $ (' s1 '). innerhtml= '; return true;}
Note: S1 for judging the content, add in the input box after <span id= ' s1 ' ></span>
3. Verify the password
function Checkpwd () { //Get value ditto ... Judgment cannot be empty Ibid ... The regular expression var reg=/^\s{6,}$/; Detects if the input matches the regular expression if (reg.test (password) ==false) { $ (' s2 '). innerhtml= ' Password must be more than 6 bits '; return false; } Match, return null ibid ...}
4. Verify the Mailbox
function Checkemail () { //Get value ditto ... Judgment cannot be empty Ibid ... The regular expression var reg=/^\w+@\w+\.com|cn|net$/; Detects if the input matches the regular expression if (!reg.test (email)) { $ (' S3 '). Innerhtml= ' email is illegal '; return false; } Match, return null ibid ...}
5. Verify the phone number
function Checktel () { //Get value ditto ... Judgment cannot be empty Ibid ... The regular expression var reg=/^1[34578]\d{9}$/; Detects if the input matches the regular expression if (!reg.test (tel)) { $ (' S4 '). Innerhtml= ' mobile phone number is not legal '; return false; } Match, return null ibid ...}
6. Verify the ID number
function Checkcid () { //Get value ditto ... Judgment cannot be empty Ibid ... The regular expression var reg=/^\d{15}$|^\d{17}\d|x$/; Detects if the input matches the regular expression if (!reg.test (CID)) { $ (' S5 '). Innerhtml= ' identity card is not legal '; return false; } Match, return null ibid ...}
7. Verify QQ number
function Checkqq () { //Get value ditto ... Judgment cannot be empty Ibid ... The regular expression var reg=/^[1-9]\d{7,10}$/; Detects if the input matches the regular expression if (!reg.test (QQ)) { $ (' S6 '). Innerhtml= ' QQ must be 8 to 11 digits, the beginning cannot be 0 '; return false; } Match, return null ibid ...}
8. Detect all Conditions
function Checkall () { if (CheckName () &&checkpwd () &&checkemail () &&checktel () & &checkcid () &&checkqq ()) { return true; } else{ return false; }}
Of course, it is more convenient to use the jquery Validate validation framework for expression validation at a later stage.
The above content is the regular expression registry verification Note collation, I hope to help everyone.