Common JS string judgment method finishing _javascript skill

Source: Internet
Author: User
Tags rtrim
JS Tools-js Common methods, JS commonly used to judge methods
SUMMARY:
Copy Code code as follows:

function obj$ (ID) Get object based on ID
function val$ (ID) Gets the value of an object based on the ID
function Trim (str) remove left and right spaces
function LTrim (str) Delete left space
function RTrim (str) Remove the right space
Whether a function IsEmpty (str) string has a value
function Equals (str1, str2) JS determines whether two strings are equal
function Equalsignorecase (str1, str2) JS determines whether two strings are equal by ignoring case
function Ischinese (str) JS to determine whether Chinese
function Isemail (stremail) JS determines whether e-mail
function isimg (str) JS Determines whether the file is a picture format jpg|jpeg|swf|gif
function Isinteger (str) JS Determines whether it is an integer
Function Isfloat JS Determines whether it is a floating-point number
function IsPost (str) JS to determine whether ZIP code (1 to 6 digits)
function IsMobile (str) JS to determine whether the cell phone number
function Isphone (str) JS determines whether the phone number must contain an area code and can contain an extension number
function isqq (str) JS to determine whether the legal QQ number
function IsIP (str) JS to determine whether it is a legitimate IP
function IsDate (str) JS determines whether the date type (example: 2005-12-12)
function Isidcardno (idNumber) JS to determine whether it is a legal ID number
*/

function obj$ (ID)
{
return document.getElementById (ID);
}


function val$ (ID)
{
var obj = document.getElementById (ID);
if (obj!== null)
{
return obj.value;
}
return null;
}


function Trim (str)
{
Return Str.replace (/(^\s*) | ( \s*$)/g, "");
}


function LTrim (str)
{
Return Str.replace (/^\s*/g, "");
}


function RTrim (str)
{
Return Str.replace (/\s*$/, "");
}


function IsEmpty (str)
{
if (str!= null && str.length > 0)
{
return true;
}
return false;
}


function Equals (str1, str2)
{
if (str1 = = str2)
{
return true;
}
return false;
}


function Equalsignorecase (str1, STR2)
{
if (str1.touppercase () = = Str2.touppercase ())
{
return true;
}
return false;
}


function Ischinese (str)
{
var str = str.replace (/(^\s*) | ( \s*$)/g, "");
if (!) ( /^[\u4e00-\ufa29]*$/.test (str)
&& (!/^[\ue7c7-\ue7f3]*$/.test (str)))
{
return false;
}
return true;
}


function Isemail (str)
{
if (/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$/.test (str))
{
return True
}
return false;
}


function isimg (str)
{
var objreg = new RegExp ("[.] + (Jpg|jpeg|swf|gif) $ "," GI ");
if (Objreg.test (str))
{
return true;
}
return false;
}


function Isinteger (str)
{
if (/^-?\d+$/.test (str))
{
return true;
}
return false;
}


function Isfloat (str)
{
if (/^ (-?\d+) (\.\d+)? $/.test (str)
{
return true;
}
return false;
}


function IsPost (str)
{
if (/^\d{1,6}$/.test (str))
{
return true;
}
return false;
}


function IsMobile (str)
{
if (/^1[35]\d{9}/.test (str))
{
return true;
}
return false;
}


function Isphone (str)
{
if (/^ (0[1-9]\d{1,2}-) \d{7,8} (-\d{1,8})/.test (str))
{
return true;
}
return false;
}


function isqq (str) {
if (/^\d{5,9}$/.test (str))
{
return true;
}
return false;
}


function IsIP (str) {
var reg =/^ (25[0-5]|2[0-4][0-9]|[ 0-1]{1}[0-9]{2}| [1-9] {1} [0-9] {1}| [1-9]) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [1-9]|0) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [1-9]|0) \. (25[0-5]|2[0-4][0-9]| [0-1] {1} [0-9] {2}| [1-9] {1} [0-9] {1}| [0-9]) $/;
if (. Test (str))
{
return true;
}
return false;
}


function IsDate (str)
{
var reg =/^ (((1[6-9]|[ 2-9]\d) \d{2})-(0?[ 13578]|1[02])-(0?[ 1-9]| [12]\d|3[01]) | (((1[6-9]| [2-9]\d) \d{2})-(0?[ 13456789]|1[012])-(0?[ 1-9]| [12]\d|30)] | (((1[6-9]| [2-9]\d) \d{2}) -0?2-(0?[ 1-9]|1\D|2[0-8]) | (((1[6-9]| [2-9]\d) (0[48]|[ 2468][048]| [13579] [26]) | ((16| [2468] [048]| [3579] [26]) 00)) -0?2-29-) $/;
if (Reg.test (str))
{
return true;
}
return false;
}


function Isidcardno (idNumber)
{
var Factorarr = new Array (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
var vararray = new Array ();
var lngproduct = 0;
var intcheckdigit;
var idnumber.length =;

if ((Idnumber.length!=) && (idnumber.length!= 18))
{
return false;
}
for (i=0;i<idnumber.length;i++)
{
Vararray[i] = Idnumber.charat (i);
if ((Vararray[i] < ' 0 ' | | | vararray[i] > ' 9 ') && (i!= 17))
{
return false;
}
else if (I < 17)
{
Vararray[i] = Vararray[i]*factorarr[i];
}
}
if (idnumber.length = 18)
{
var Date8 = idnumber.substring (6,14);
if (checkdate (date8) = = False)
{
return false;
}
for (i=0;i<17;i++)
{
Lngproduct = lngproduct + vararray[i];
}
Intcheckdigit = 12-lngproduct% 11;
Switch (intcheckdigit)
{
Case 10:
Intcheckdigit = ' X ';
Break
Case 11:
Intcheckdigit = 0;
Break
Case 12:
Intcheckdigit = 1;
Break
}
if (Vararray[17].touppercase ()!= intcheckdigit)
{
return false;
}
}
Else
{
var date6 = idnumber.substring (6,12);
if (checkdate (date6) = = False)
{
return false;
}
}
return true;
}

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.