JS Common 2 Comparison of the commonly used functions 1th/3 page _javascript Tips

Source: Internet
Author: User
/*
-------------------------------------------------------------------------------
File name: Check.js
Description: JavaScript script, used to check the input data of the Web page submission Form
Version: 1.0
*/
/*
Purpose: Verify the format of IP address
Input: Strip:ip Address
Returns: False if return true through validation;
*/
function IsIP (StrIP) {
if (IsNull (StrIP)) return false;
var re=/^ (\d+) \. (\d+) \. (\d+) \. (\d+) $/g//matching the regular expression of the IP address
if (Re.test (StrIP))
{
if (regexp.$1 <256 && regexp.$2<256 && regexp.$3<256 && regexp.$4<256) return true;
}
return false;
}
/*
Purpose: Check if the input string is empty or all are spaces
Input: str
Return:
Returns true if all is null, or False
*/
function IsNull (str) {
if (str = = "") return true;
var Regu = "^[]+$";
var re = new RegExp (Regu);
return Re.test (str);
}
/*
Purpose: Check whether the value of the input object conforms to the integer format
Input: str input string
Return: False if return true through validation
*/
function Isinteger (str) {
var regu =/^[-]{0,1}[0-9]{1,}$/;
return Regu.test (str);
}
/*
Purpose: Check whether the input mobile phone number is correct
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Checkmobile (s) {
var regu =/^[1][3][0-9]{9}$/;
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
}else{
return false;
}
}
/*
Purpose: Check if the input string conforms to the positive integer format
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isnumber (s) {
var Regu = "^[0-9]+$";
var re = new RegExp (Regu);
if (S.search (re)!=-1) {
return true;
} else {
return false;
}
}
/*
Purpose: Check if the input string is a decimal number format, can be negative
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isdecimal (str) {
if (Isinteger (str)) return true;
var re =/^[-]{0,1} (\d+) [\.] + (\d+) $/;
if (Re.test (str)) {
if (regexp.$1==0&&regexp.$2==0) return false;
return true;
} else {
return false;
}
}
/*
Purpose: Check if the value of the input object conforms to the port number format
Input: str input string
Return: False if return true through validation
*/
function Isport (str) {
Return (Isnumber (str) && str<65536);
}
/*
Purpose: Check if the value of the input object conforms to the e-mail format
Input: str input string
Return: False if return true through validation
*/
function Isemail (str) {
var myreg =/^[-_a-za-z0-9]+@ ([_a-za-z0-9]+\.) +[a-za-z0-9]{2,3}$/;
if (Myreg.test (str)) return true;
return false;
}
/*
Purpose: Check whether the input string conforms to the amount format
The format is defined as a positive number with decimals, with a maximum of three digits after the decimal point
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Ismoney (s) {
var Regu = "^[0-9]+[\." [0-9] {0,3}$ ";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
} else {
return false;
}
}
/*
Purpose: Check if the input string is composed of English letters and numbers and underscores only
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isnumberor_letter (s) {//Judge whether it is a number or letter
var Regu = "^[0-9a-za-z\_]+$";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
}else{
return false;
}
}
/*
Purpose: Check if the input string is made up of English letters and numbers only
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isnumberorletter (s) {//Judge whether it is a number or letter
var Regu = "^[0-9a-za-z]+$";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
}else{
return false;
}
}
/*
Purpose: Check if the input string is composed of Chinese characters, letters and numbers only
Input:
Value: String
Return:
Returns False if the validation returns true
*/
function Ischinaornumborlett (s) {//Judge whether it is Chinese characters, letters, numbers
var Regu = "^[0-9a-za-z\u4e00-\u9fa5]+$";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
}else{
return false;
}
}
/*
Use: Determine whether the date
Enter: Date: dates; FMT: date format
Return: False if return true through validation
*/
function isDate (date, FMT) {
if (fmt==null) fmt= "YYYYMMDD";
var yindex = fmt.indexof ("yyyy");
if (yindex==-1) return false;
var year = date.substring (yindex,yindex+4);
var mindex = Fmt.indexof ("MM");
if (mindex==-1) return false;
var month = date.substring (mindex,mindex+2);
var dindex = Fmt.indexof ("dd");
if (dindex==-1) return false;
var day = date.substring (dindex,dindex+2);
if (!isnumber) | | Year> "2100" | | year< "1900") return false;
if (!isnumber (month) | | Month> "12" | | month< "") return false;
if (Day>getmaxday (year,month) | | | | day< ") return false;
return true;
}
function Getmaxday (year,month) {
if (month==4| | month==6| | month==9| | MONTH==11)
return "30";
if (month==2)
if (year%4==0&&year%100!=0 | | year%400==0)
return "29";
Else
Return "28";
return "31";
}
/*
Usage: Character 1 ends with string 2
Input: str1: string; str2: contained string
Return: False if return true through validation
*/
function Islastmatch (STR1,STR2)
{
var index = str1.lastindexof (STR2);
if (str1.length==index+str2.length) return true;
return false;
}
/*
Usage: Character 1 starts with string 2
Input: str1: string; str2: contained string
Return: False if return true through validation
*/
function Isfirstmatch (STR1,STR2)
{
var index = str1.indexof (STR2);
if (index==0) return true;
return false;
}
Current 1/3 page 123 Next read the full text

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.