Regular check collation

Keywords: Mobile IE Windows ftp

1. Check basic date format

var reg1 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;

var reg2 = /^(^(\d{4}|\d{2})(\-|\/|\.)\d{1,2}\3\d{1,2}$)|(^\d{4}year\d{1,2}month\d{1,2}day $)$/;

 

2. Verify password strength

The strength of a password must be a combination of upper and lower case letters and numbers. No special characters can be used, and the length is between 8 and 10.

var reg = /^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$/;

3. Verify Chinese

Strings can only be Chinese.

var reg = /^[\\u4e00-\\u9fa5]{0,}$/;

4. Strings consisting of numbers, 26 English letters or underscores

var reg = /^\\w+$/;

5. Verify E-Mail address

As with passwords, here are the regular check statements for E-mail address compliance.

var reg = /[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?/;

6. Verify your ID number

Below is a regular check of the ID number.15 or 18 bits.

15:

var reg = /^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$/;

18 bits:

var reg = /^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$/;

7. Verification date

"yyyy-mm-dd" format date check, leap year considered.

var reg = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;

8. Validation amount

Value check, accurate to 2 decimal places.

var reg = /^[0-9]+(.[0-9]{2})?$/;

9. Verify your mobile phone number

Below is the regular expression of mobile phone number starting with 13, 15 and 18 in China.(The first two digits starting number can be expanded according to the current domestic collection number)

var reg = /^(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}$/;

10. Determine the version of IE

IE has not been completely replaced yet. Many pages still need version compatibility. Here is the expression for IE version checking.

var reg = /^.*MSIE [5-8](?:\\.[0-9]+)?(?!.*Trident\\\/[5-9]\\.0).*$/;

11. Verify IP-v4 address

var reg = /\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b/;

12. Verify IP-v6 addresses

var reg = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/;

13. Check the prefix of the URL

In application development, it is often necessary to distinguish whether a request is HTTPS or HTTP. The following expression allows you to prefix a url and make logical decisions.

if (!s.match(/^[a-zA-Z]+:\/\//)) {

s = 'http://' + s;

}

14. Extract URL Links

This expression below filters out URL s in a piece of text.

var reg = /^(f|ht){1}(tp|tps):\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/;

15. File Path and Extension Check

Verify the file path and extension under windows (the.txt file in the example below)

var reg = /^([a-zA-Z]\\:|\\\\)\\\\([^\\]+\\)*[^\\/:*?"<>|]+\\.txt(l)?$/;

16. Extract Color Hex Codes

Sometimes you need to extract the color code from a web page, you can use the following expression.

var reg = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;

17. Extract pictures from web pages

If you want to extract all the picture information from the web page, you can use the following expression.

var reg = /\\< *[img][^\\>]*[src] *= *[\\"\']{0,1}([^\\"\'\ >]*)/;

18. Extract page hyperlinks

Extract hyperlinks from html.

var reg = /(<a\\s*(?!.*\\brel=)[^>]*)(href="https?:\/\/)((?!(?:(?:www\\.)?'.implode('|(?:www\\.)?', $follow_list).'))[^"]+)"((?!.*\\brel=)[^>]*)(?:[^>]*)>/;

19. Find CSS Properties

The following expression allows you to search for matching CSS attributes.

var reg = /^\\s*[a-zA-Z\\-]+\\s*[:]{1}\\s[a-zA-Z0-9\\s.#]+[;]{1}/;

20. Extract Notes

If you need to remove comments from HMTL, you can use the following expression.

var reg = /<!--(.*?)-->/;

21. Capital letters

var reg = /^[A-Z]+$/;

22. Lower case letters

var reg = /^[a-z]+$/;

23. Uppercase and lowercase letters

var reg = /^[A-Za-z]+$/;

24. Positive Integer

var reg = /^[1-9]\d*$/;

23. Identify your mobile phone or landline

var reg = /^[A-Za-z]+$/;

24. Legal URLs

var reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;

Posted by reneeshtk on Thu, 09 May 2019 06:03:38 -0700