JS-EL Regular expression

Source: Internet
Author: User

<script>

Check whether the total number consists of 20 digits

var patrn=/^[0-9]{1,20}$/;
Alert (Patrn.test ("-30000000000"));


Check login name: Only 5-20 entries begin with a letter, can be numbered, "_", "." The string

var patrn=/^[a-za-z]{1} ([a-za-z0-9]|[. _]) {4,19}$/;
Alert (patrn.test (' a_1111 '));

Verify user name: Only 1-30 strings beginning with a letter/underscore can be entered

var patrn=/^ ([a-za-z]|[ _]) {1,30}$/;
Alert (patrn.test (' _aaaaa '));


Check password: Only 6-20 letters, numbers, underscores can be entered
function ispasswd (s)
{
var patrn=/^ (\w) {6,20}$/;
if (!patrn.exec (s)) return false
return True
}

Check the ordinary telephone, fax number: Can "+" start, in addition to the number, can contain "-"
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
}
Check mobile phone Number: Must start with a number, except the number, can contain "-"
function Ismobil (s)
{
var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +$/;
if (!patrn.exec (s)) return false
return True
}
Verifying ZIP Codes
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
}
Verifying search Keywords
function Issearch (s)
{
var patrn=/^[^ ' [email protected]#$%^&* () +=|\\\][\]\{\}:; ' \,.<>/?] {1} [^ ' [email protected]$%^& () +=|\\\] [\]\{\}:;‘ \,.<>?] {0,19}$/;
if (!patrn.exec (s)) return false
return True
}
function IsIP (s)//by zergling
{
var patrn=/^[0-9.] {1,20}$/;
if (!patrn.exec (s)) return false
return True
}


function CheckMobile1 (form)
{
if (Form.mobile.value > "")
{
var reg=/13[5,6,7,8,9]\d{8}/;
if (Form.mobile.value.match (reg) = = null)
{
Alert ("Please enter the correct mobile phone number!") ");
Form.mobile.focus (); return false;
}
}
return true;
}

Clear left and right spaces

var aa= ' 1 ASD 123 ASD! ‘;
Alert (Aa.replace (/(^\s*) | ( \s*$)/g, ""));

jquery method

Alert ($.trim ("AB C"));

The checksum of the URL,

OBJ: Data Object
Dispstr: Failed prompt content display string
function Checkurlvalid (obj, dispstr)
{
if (obj = = null)
{
Alert ("The Incoming object is empty");
return false;
}
var str = obj.value;

var urlpatern0 =/^https?:\ /\/.+$/i;
if (!urlpatern0.test (str))
{
Alert (dispstr+ "illegal: Must start with ' http:\/\/' or ' https:\/\/'!");
Obj.focus ();
return false;
}

var urlpatern2=/^https?:\ /\/([a-za-z0-9_-]) + (\.)?) * (: \d+)? +$/i;
if (!urlpatern2.test (str))
{
Alert (dispstr+ "port number must be a number and should be between 1-65535!");
Obj.focus ();
return false;
}


var urlpatern1 =/^https?:\ /\/([a-za-z0-9_-]) + (\.)?) * (: \d+)? (\/((\.)? (\?)? =?&? [a-za-z0-9_-] (\?)?) *) *$/i;

if (!urlpatern1.test (str))
{
Alert (dispstr+ "illegal, please check!");
Obj.focus ();
return false;
}

var s = "0";
var t = 0;
var re = new RegExp (": \\d+", "IG");
while (arr = re.exec (str))!=null)
{
s = str.substring (Regexp.index+1,regexp.lastindex);

if (s.substring (0,1) = = "0")
{
Alert (dispstr+ "port number cannot start with 0!");
Obj.focus ();
return false;
}

T = parseint (s);
if (t<1 | | t >65535)
{
Alert (dispstr+ "port number must be a number and should be between 1-65535!");
Obj.focus ();
return false;
}
}
return true;
}

</script>

JS-EL Regular expression

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.