concept
Regular expressions are a logical formula for string operations, which is to use some specific characters defined in advance and combinations of these specific characters to form a "rule string". This "rule string" is used to express a filtering logic for strings.
Introduction
Regular expressions are a logical formula for operating strings (including ordinary characters (such as letters between a to z) and special characters (called "metacharacters"). They are to use some specific characters defined in advance and the combination of these specific characters to form a "rule string". This "rule string" is used to express a filtering logic for strings. A regular expression is a text pattern that describes one or more strings to match when searching for text.
Front-end regular expression verification is often the most numerous and complex, so I have sorted out some regular expressions I have used recently, hoping that it will be helpful to everyone!
/* Legal uri */ export function validateURL(textval) { const urlregex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/ return (textval) } /* Lowercase letters */ export function validateLowerCase(str) { const reg = /^[a-z]+$/ return (str) } /* uppercase letter */ export function validateUpperCase(str) { const reg = /^[A-Z]+$/ return (str) } /* uppercase and uppercase letters */ export function validateAlphabets(str) { const reg = /^[A-Za-z]+$/ return (str) } /* Market price */ export function validatePrice(str) { const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/ return (str) } /* Inventory warning value Match non-negative integers (positive integer + 0) */ export function validatestockWarn(str) { const reg = /^(0|[1-9][0-9]*)$/ return (str) } /* Price comparison website Only verify JD and Suning websites */ export function validateCompareWebsite(str) { const reg = /^((https\:\/\/[0-9a-zA-Z\_]+\.|http\:\/\/[0-9a-zA-Z\_]+\.|https\:\/\/|http\:\/\/)|([0-9a-zA-Z\_]+\.){0,1})(jd|suning)\.(com$|com\/[\S]*)/i return (str) } /* Landline phone */ export function validateTelephone(str) { const reg = /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/ return (str) } /* phone number */ export function validatePhoneNumber(str) { const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/ return (str) } /* Mobile phone number and landline phone */ export function validatePhTelNumber(str) { const reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/ return (str) } /* Email */ export function validateEmail(str) { const reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/ return (str) } /* post code */ export function validateZipCode(str) { const reg = /^[1-9][0-9]{5}$/ return (str) } /* ID card */ export function validateIDCard(str) { const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/ return (str) } /* Bank card number 15 or 16 or 19 */ export function validateBank(str) { const reg = /^([1-9]{1})(\d{14}|\d{18}|\d{15})$/ return (str) } /* Taxpayer identification code */ export function validateTaxpayer(str) { const reg = /^([1-9]{1})(\d{14}|\d{18}|\d{15})$/ return (str) } /* Match all spaces */ export function validateAllBlank(str) { const reg = /^\s+$/gi return (str) }
Summarize
The above is the 2019 mobile phone number JS regular expression verification example code introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!