Home > Web Front-end > JS Tutorial > body text

Practical JS regular expressions (mobile phone number/IP regular expression/zip code regular expression/telephone number, etc.)_javascript skills

WBOY
Release: 2016-05-16 17:43:50
Original
1276 people have browsed it

//Check whether it is composed entirely of numbers

Copy code The code is as follows:

function isDigit( s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}

//Verify login name: You can only enter 5-20 character strings starting with letters, with numbers, "_", and "."
Copy code The code is as follows:

function isRegisterUserName(s)
{
var patrn=/^[a- zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
if (!patrn.exec(s)) return false
return true
}

//Verify user name: only 1-30 strings starting with letters can be entered
Copy Code The code is as follows:

function isTrueName(s)
{
var patrn=/^[a-zA-Z]{1,30 }$/;
if (!patrn.exec(s)) return false
return true
}

//Verification password: only 6-20 can be entered Letters, numbers, underscores
Copy code The code is as follows:

function isPasswd(s)
{
var patrn=/^(w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}

//Verify ordinary telephone and fax numbers: it can start with " ", and in addition to numbers, it can contain "-"
Copy code The code is as follows:

function isTel(s)
{
//var patrn=/^[ ]{0,1}(d){1,3} [ ]?([-]?(d){1,12}) $/;
var patrn=/^[ ]{0,1}(d){1,3}[ ]?([-] ?((d)|[ ]){1,12}) $/;
if (!patrn.exec(s)) return false
return true
}

//Verify mobile phone number: must start with a number. In addition to numbers, it can contain "-"
Copy code The code is as follows :

function isMobil(s)
{
var patrn=/^[ ]{0,1}(d){1,3}[ ]?([-]? ((d)|[ ]){1,12}) $/;
if (!patrn.exec(s)) return false
return true
}

//Verify postal code
Copy code The code is as follows:

function isPostalCode(s)
{
//var patrn=/^[a-zA-Z0-9]{3,12}$/;
var patrn=/^[a-zA-Z0-9 ]{3, 12}$/;
if (!patrn.exec(s)) return false
return true
}

//Verify search keywords
Copy code The code is as follows:

function isSearch(s)
{
var patrn=/^ [^`~!@#$%^&*() =|][]{}:;',.<>/?]{1}[^`~!@$%^&() =| ][]{}:;',.<>?]{0,19}$/;
if (!patrn.exec(s)) return false
return true
}

//Check whether the IP address is
Copy code The code is as follows:

function isIP(s) //by zergling
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}

Copy code The code is as follows:

"^d $" //음이 아닌 정수(양의 정수 0)
"^[0-9]*[1-9][0-9]*$" //양의 정수
"^((-d )|(0 ))$" //양수가 아닌 정수(음의 정수 0)
"^-[0-9]*[1-9][0-9] *$ " //음의 정수
"^-?d $" //정수
"^d (.d )?$" //음이 아닌 부동 소수점 수(양의 부동 소수점 수 0)
"^(( [0-9] .[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[ 0-9] ) |([0-9]*[1-9][0-9]*))$" //양수 부동 소수점 숫자
"^((-d (.d )?)| (0 (.0 ) ?))$" //양수가 아닌 부동 소수점 숫자 (음의 부동 소수점 숫자 0)
"^(-(([0-9] .[0-9]*[1- 9][0-9]*) |([0-9]*[1-9][0-9]*.[0-9] )|([0-9]*[1-9][0 -9]*)))$" //음수 부동 소수점 수
"^(-?d )(.d )?$" //부동 소수점 수
"^[A-Za-z] $ " //영문 26자로 구성된 문자열
"^[A-Z] $" //영문 대문자 26자로 구성된 문자열
"^[a-z] $" //영문 소문자 26자로 구성된 문자열 letter
"^[A-Za-z0-9] $" // 숫자와 영문 26자로 구성된 문자열
"^w $" // 숫자와 영문 26자, 밑줄로 구성된 문자열
"^w $" // 숫자와 영문 26자로 이루어진 문자열
🎜>"^[w-] (.[w-] )*@[w-] (.[w-] ) $"   //이메일 주소
"^[a-zA-z] ://( w (-w )*)(.(w (-w )*))*(?S*)?$" //url
"^[A-Za-z0-9_]*$"
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!