Last active
July 17, 2024 07:12
-
-
Save Alex1990/0ec0f808609a20155bf9 to your computer and use it in GitHub Desktop.
Common regular expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Common regular expressions | |
| */ | |
| var rules = { | |
| alphabet: /^[a-zA-Z]+$/, | |
| numeric: /^[0-9]+$/, | |
| alphanumeric: /^[0-9a-zA-Z]+$/, | |
| alphadash: /^[0-9a-zA-Z_]+$/, | |
| ascii: /[\x00-\xff]/, | |
| nonascii: /[^\x00-\xff]/ | |
| fullWidth: /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE]/, | |
| halfWidth: /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE]/, | |
| number: /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[e|E][+-]?\d+)?$/, | |
| factional: /^[+-]?\d*\.\d+$/, | |
| base64: /^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i, | |
| email: /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~])*@[a-zA-Z](-?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$/, | |
| domain: /^((https?):\/\/)?[^\s].[^\s]*$/i, | |
| url: /^(https?|ftp):\/\/[^\s].[^\s]*$/i, | |
| ip: /^(?:25[0-5]|2[0-4][0-9]|1\d{2}|[1-9]\d?)\.(?:(?:25[0-5]|2[0-4][0-9]|1\d{2}|[1-9]?\d)\.){2}(?:25[0-5]|2[0-4][0-9]|1\d{2}|[1-9]?\d)$/, | |
| phone: /^1\d{10}$/, | |
| zipcode: /^\d{6}$/ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment