Regular check tool : https://c.runoob.com/front-end/854
Reference from : http://blog.csdn.net/kiss_vicente/article/details/8050816
Common regular expressions:
- ^\d+$ // matches non-negative integers (positive integers + 0)
- ([1-9]{1}\\d*|\\d{1})[.]{0,1}\\d{0,2} //Judgment value (amount)
- ^[0-9]*[1-9][0-9]*$ //Matches positive integers
- ^[1-9]\d*$ ////Match non-integer
- ^[1-9]\d* ¦0$ //Matches non-negative positive integers
- ^((-\d+) ?(0+))$ // matches non-positive integers (negative integers + 0)
- ^-[0-9]*[1-9][0-9]*$ //Matches negative integers
- ^-?\d+$ // match integer
- ^\d+(\.\d+)?$ // matches non-negative float (positive float + 0)
- ^(([0-9]+\.[0-9]*[1-9][0-9]*) ?([0-9]*[1-9][0-9]*\. [0-9]+) ?([0-9]*[1-9][0-9]*))$ //Match positive floating point numbers
- ^((-\d+(\.\d+)?) ?(0+(\.0+)?))$ // matches non-positive floats (negative floats + 0)
- ^(-(([0-9]+\.[0-9]*[1-9][0-9]*) ?([0-9]*[1-9][0-9]* \.[0-9]+) ?([0-9]*[1-9] [0-9]*)))$ //Matches negative floating point numbers
- ^(-?\d+)(\.\d+)?$ //Match floating point numbers
- ^[A-Za-z]+$ //Matches a string consisting of 26 English letters
- ^[AZ]+$ //Matches a string consisting of uppercase 26 English letters
- ^[az]+$ //match a string consisting of 26 lowercase English letters
- ^[A-Za-z0-9]+$ //Matches a string consisting of numbers and 26 English letters
- ^\w+$ //Matches a string consisting of numbers, 26 English letters or underscores
- ^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$ // match email address
- [a-zA-z] +: // [^ \ s] * // Matching url
- [\u4e00-\u9fa5] //Regular expression matching Chinese characters
- [^\x00-\xff] //Match double-byte characters (including Chinese characters)
- String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;} Calculate the length of the string (a double-byte character length counts as 2, ASCII character meter 1)
- \n[\s ? ]*\r //regular expression matching blank lines
- / <(.*)>.* <\/\1> ? <(.*) \/>/ // Regular expression matching HTML tags
- (^\s*) ?(\s*$) //regular expression matching leading and trailing spaces
- [\u4e00-\u9fa5] //Regular expression matching Chinese characters
- \d{3}-\d{8} ?\d{4}-\d{7} //Matches domestic phone numbers 0511-4405222 or 021-87888822
Regular Expression Use Cases
- ^\S+[az AZ]$ No //Can be empty, no spaces, only English letters
- \S{6,} //Cannot be more than six digits
- ^\d+$ //No spaces and no non-digits
- (.*)(\.jpg ?\.bmp)$ //Only jpg and bmp formats
- ^\d{4}\-\d{1,2}-\d{1,2}$ //Only 2004-10-22 format
- ^0$ // choose at least one
- ^0{2,}$ //Select at least two
- ^[\s ?\S]{20,}$ //Cannot be more than 20 characters
- ^ \ +? [A-z0-9] (([-+.]? [_] +)? [A-z0-9] +) * @ ([a-z0-9] + (\.? \ -)) + [az] {2,6} $ // Mail
- \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([- +.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)* //Enter multiple addresses to separate emails with commas or spaces
- ^([0−9]+)?[0-9]{7,8}$ Phone number with 7 or 8 digits or area code in front such as (022) 87341628
- ^\w+@\w+(\.\w+)+(\,\w+@\w+(\.\w+)+)*$ //Can only be letters, numbers, underscores; there must be @ and . canonical mail
Match specific numbers:
^[1-9]\d*$ //match positive integers
^-[1-9]\d*$ //match negative integers
^-?[1-9]\d*$ //match Integer
^[1-9]\d* ¦0$ //matches non-negative integers (positive integers + 0)
^-[1-9]\d* ¦0$ //matches non-positive integers (negative integers + 0)
^[ 1-9]\d*\.\d* ¦0\.\d*[1-9]\d*$ //Matches positive float
^-([1-9]\d*\.\d* ¦0 \.\d*[1-9]\d*)$ //Matches negative float
^-?([1-9]\d*\.\d* ¦0\.\d*[1-9]\ d* ¦0?\.0+ ¦0)$ //Matches a float
^[1-9]\d*\.\d* ¦0\.\d*[1-9]\d* ¦0?\.0+ ¦0$ //Matches non-negative floats (positive floats + 0)
^(-([1-9]\d*\.\d* ¦0\.\d*[1-9]\d*)) ¦0 ?\.0+ ¦0$ // match non-positive float (negative float + 0)