JS Verification Mobile phone number, nickname, password

Source: Internet
Author: User

Phone number
/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +$/

Fax ~
/^ (\d{3,4}-)? \d{7,8}$/
Mailbox
^[a-z0-9]+ ([. _\\-]*[a-z0-9]) *@ ([a-z0-9]+[-a-z0-9]*[a-z0-9]+.) {1,63} [a-z0-9]+$
Url
/^ ([0-9]| [1-9]\d|1\d\d|2[0-4]\d|25[0-5]) \. ([0-9]| [1-9]\d|1\d\d|2[0-4]\d|25[0-5]) \. ([0-9]| [1-9]\d|1\d\d|2[0-4]\d|25[0-5]) \. ([0-9]| [1-9]\d|1\d\d|2[0-4]\d|25[0-5]) $/;

var reg =/^1[0-9]{10}$/;

function Checkphone () {

var phone = document.getElementById (' phone '). Value;
if (! ( /^1[3|4|5|7|8]\d{9}$/.test (phone))) {
Alert ("The phone number is wrong, please re-fill");
return false;
}

}

var check =/^[0-9]{6}$/;
var partten = ^[a-z0-9]+ ([. _\\-]*[a-z0-9]) *@ ([a-z0-9]+[-a-z0-9]*[a-z0-9]+.) {1,63} [a-z0-9]+$;
var checkfax =/^ (\d{3,4}-)? \d{7,8}$/;
Verify the form
if (companyname==null| | companyname== "") {
$ (' #ajaxinfo '). html (' <br><font color= ' red ' > name is not empty and cannot be greater than 40 characters </font> ');
return false;
}
var str =companyname.split ("");
CompanyName = "";
for (var i = 0;i<str.length;i++)
{
if (str[i]== "") {
Str[i] = "";
}
if (Str[i].indexof ("")!=-1) {
Str[i].replace ("," "");
}
CompanyName + = "" +str[i];
}
if (!partten.test (CompanyName)) {
$ (' #ajaxinfo '). html (' <br><font color= ' red ' > name can only be in Chinese and English (may contain spaces) </font> ');
return false;
}
if (!checkmobile ()) {
return false;
}
if (!checkname ()) {
return false;
}
if (!checkaddresslength ()) {
return false;
}
if (fax!= "") {
if (!checkfax.test (fax)) {
Aert (fax);
Alert ("Fax format: XXX-12345678 or XXXX-1234567 or XXXX-12345678");
return false;
}
}
if (postcode!= "") {
if (!check.test (postcode)) {
Alert ("ZIP code is incorrect!");
return false;
}
}

See a lot of code on the Internet is very complex, but also includes the beginning of the Chinese 86,17951, in fact, who will fill so much, is nothing more than to test whether they are the right number, the beginning is not written wrong just. Below we from the Baidu Encyclopedia mobile phone number process to see: Now mobile phone number segment has unicom, mobile and telecommunications.

Telecom

China Telecom mobile phone number start number
2G/3G segment (CDMA2000 network) 133, 153, 180, 181, 189
Section 4G, 177

Unicom

China Unicom mobile phone number start number
Segment 2G (GSM network) 130, 131, 132, 155, 156
3G Internet Card 145
Segment 3G (WCDMA network) 185, 186
Segment 4G 176, 185[1]


Move


China Mobile phone number start number
The 2G segment (GSM network) has 134x (0-8), 135, 136, 137, 138, 139, 150, 151, 152, 158, 159, 182, 183, 184.
Segment 3G (TD-SCDMA Network) 157, 187, 188
3G Internet Card 147
Section 4G, 178


From the above we can see that the first is the beginning of "1", the second is "3,4,5,7,8", the third is "0-9", the third is the number "0-9". So we can draw a regular expression that matches the current cell phone number verification.

var // validation rules var phonenum = ' 15507621999 '; // Mobile phone number var // true but have you thought about it, maybe this second code might add one at a time, like starting with 16? What about the beginning of 19? Who knows the future, our code to guarantee a few years no problem, so you can also do not verify the second rule:

Password verification

User name Verification

function RR (val) {  =/^[\u4e00-\u9fa5]{2,4}$/;   if (! Reg.test (val)) {   document.getElementById (' t '). InnerHTML = ' does not meet the standard! ';  } Else {   document.getElementById (' t '). InnerHTML = ' conforms to the standard! ';  } }

JS Verification Mobile phone number, nickname, password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.