Some JS code for checking the data

Source: Internet
Author: User
Tags rtrim trim valid
js| data

These JS code are some of the form submitted in the code often used, most of the code is written with regular expressions!


Go to the left space;
function LTrim (s) {
Return S.replace (/^\s*/, "");
}
Go to the right space;
function RTrim (s) {
Return S.replace (/\s*$/, "");
}
Left and right space;
function Trim (s) {
return RTrim (LTrim (s));
}
is a null value;
function IsEmpty (_STR) {
var tmp_str = trim (_STR);
return tmp_str.length = = 0;
}
whether the effective email;
function IsMail (_STR) {
var tmp_str = trim (_STR);
var pattern =/^[_a-z0-9-]+ (. [ _a-z0-9-]+) *@[a-z0-9-]+ (. [ a-z0-9-]+) *$/;
Return Pattern.test (TMP_STR);
}
The number of valid figures;
function Isnumber (_STR) {
var tmp_str = trim (_STR);
var pattern =/^[0-9]/;
Return Pattern.test (TMP_STR);
}
Whether the color value is valid;
function IsColor (color) {
var Temp=color;
if (temp== "") return true;
if (temp.length!=7) return false;
Return (Temp.search (/\#[a-fa-f0-9]{6}/)!=-1);
}
Whether the link is valid;
function Isurl (URL) {
var stemp;
var b=true;
Stemp=url.substring (0,7);
Stemp=stemp.touppercase ();
if ((stemp!= "http://") | | (URL.LENGTH<10)) {
B=false;
}
return b;
}
Whether the cell phone number is valid;
function IsMobile (_STR) {
var tmp_str = trim (_STR);
var pattern =/13\d{9}/;
Return Pattern.test (TMP_STR);
}



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.