Copy code code as follows:
String.prototype.trim = Function () {
Return this.replace (/(^/s*) | (/s*$)/g, "");
}
// Check whether it is the date format
function isdate (dateStr) {
var result = datestr.match (/(^(((^(1 [8-9]/d {2}) | ([2-9]/d {3})) (-) (10 | 12 | 0? [ 13578]) (-) (3 [01] | [12] [0-9] | 0? [1-9] $) | (^((1 [8-9]/d {2}) | ( [2-9]/d {3})) (-) (11 | 0? [469]) (-) (30 | [12] | 0? [1-9] $) | (^((1 [8-9]/d {2}) | ([2-9]/d {3}) (-) (0? 2) (-) (2 [0-8] | 1 [0-9] | 0? [1-9]) $) | (^([2468] [048] 00) (-) (0? 2) (-) (29) $) | ([3579 ] [26] 00) (-) (0? 2) (-) (29) $) | (^([1] [89] [0] [48] (-) (0? 2) (29) $) | (^([2-9] [0-9] [0] [48]) (-) (0? 2) (-) (29) $) | (^([1] [ 89] [2468] [048]) (-) (0? 2) (-) (29) $) | (^([2-9] [0-9] [2468] 0? 2) (-) (29) $) | (^([1] [89] [13579] [26]) (-) (0? 2) (-) (29) $) | (^ 2-9] [0-9] [13579] [26]) (-) (0? 2) (-) (29) $)/););););););););
if (result == null) {
Return "no";
}
Return "Yes";
}
// This method is consistent with the above effect above
Function Isdate2 (DATESTR) {
var result = datestr.match (/^(/d {1,4}) (-| //) (/d {1,2})/2 (/d {1,2});
if (result == null)
Return "no";
var d = new date (result [1], result [3] -1, result [4]);
If ((D.getfullyear () == Result [1] && (d.getmonth () + 1) == Result [3] && D.GetDate () == Result [4]) {) {) {) {
Return "Yes";
}
Return "no";
}
// Determine whether the input character is Chinese
function ischinese (STR) {
if (Str.Length! = 0) {{
Reg =/^[/u0391-/uffe5]+$/;
if (! reg.Test (STR)) {
// Alert ("Sorry, the type format of the string you entered is incorrect!"););
Return "no";
}
}
Return "Yes";
}
// Judging whether it is empty
Function Isempty (STR) {
if (str == NULL || Typeof Str == "underfined" || str.trim () == "") {
Return true;
} Else {
Return false;
}
}
// Fixed telephone
Function Testtelephone (Phone) {{
Var phone_reg = new regexp (/^([+] {0,1}/d {3,4} |/d {3,4}-)?/d {7,8} $/);
if (! Phone_reg.test (Phone)) {{
Return "no";
}
Return "Yes";
}
//Discount
Function Isdiscount (Discount) {
var phone_reg = new regexp (/^(0 (/., d {1,2}) | 1 | 1.00 | 1.0);
if (! Phone_reg.test (discount)) {
Return "no";
}
Return "Yes";
}
//phone number
Function testmobile (mobile) {
Var mobile_reg = new regexp (/^0 {0,1} 1 [0-9] {10} $/);
if (! Mobile_reg.test (mobile)) {
Return "no";
}
Return "Yes";
}
// QQ number starts from 10000
Function testqq (QQ) {
var QQ_reg = new regexp (/^[1-9] [0-9] {4,} $/);
if (! QQ_reg.test (QQ)) {
Return "no";
}
Return "Yes";
}
Function testmail (email) {
var email_reg = new regexp (/^/w+([-+.]/w+)*@/w+([-.]/w+)*./w+([-]/w+)*$/);
if (! Email_reg.test (email)) {
Return "no";
}
Return "Yes";
}
// The positive integer without symbols
Function testplusdigit (digit) {
var plusdigit_reg = new regexp (/^/d+$/);
if (! Plusdigit_reg.test (DIGIT)) {{
Return "no";
}
Return "Yes";
}
// double price
Function TestpriceFormat (STR) {
Var PriceFormatreg = New Regexp (/^/D+(./ D {1,2})? $/);
if (! PriceFormatreg.test (STR)) {
Return "no";
}
Return "Yes";
}
//ID card
Function testidCard (STR) {
Var IDCardReg = New RegXP (/(^/D {15} $) | (^/d {17} ([0-9] | x) $)/);
if (! Idcardreg.test (STR)) {
Return "no";
}
Return "Yes";
}
// 2012-06-19 Date Format
Function testdate (STR) {
var dateg = new regexp (/(^/d {4}-[0,1] [0-9]-[0-3] [0-9] $)/);
if (! Datereg.test (STR)) {
Return "no";
}
Return "Yes";
}
// Floating point count precise operations (plus method)
Function acadd (ARG1, ARG2) {{
var r1, r2, m, n;
try {r1 = arg1.tostring (). split (".") [1] .Length} catch (e) {R1 = 0}
try {r2 = arg2.tostring (). split (".") [1] .Length} catch (e) {R2 = 0}
m = math.pow (10, math.max (R1, R2));
n = (R1> = R2)? R1: R2;
Return ((arg1*m+arg2*m)/m) .tofixed (n);
}
Number.prototype.add = Function (ARG) {
Return acadd (arg, this);
}
// Floating point count precise operations (subtraction)
Function accsub (arg1, arg2) {{
Return acadd (ARG1, -ARG2);
}
Number.prototype.subtract = Function (ARG) {
Return account (this, arg);
}
// Floating point count precise operations (multiplication method)
Function accmul (ARG1, ARG2)
{{
varm m = 0, s1 = arg1.tostring (), s2 = arg2.tostring ();
TRY {m+= s1.split (".") [1] .Length} Catch (e) {}
TRY {m+= s2.split (".") [1] .Length} catch (e) {}
Return number (s1.replace (".", "")*number (s2.replace (".", "")/math.pow (10, m)
}
Number.prototype.mul = Function (ARG) {
Return accmul (arg, this);
}
// Floating point count precise operations (divided by method)
Function accdiv (ARG1, ARG2) {{
var T1 = 0, T2 = 0, R1, R2;
try {t1 = arg1.tostring (). split (".") [1] .Length} Catch (e) {}
try {t2 = arg2.tostring (). split (".") [1] .Length} catch (e) {}
with (math) {
R1 = Number (arg1.tostring (). Replace (".", ""))
r2 = number (arg2.tostring (). Replace (".", ""))
Return (R1/R2)*POW (10, T2-T1);
}
}
Number.prototype.div = Function (ARG) {
Return accdiv (this, arg);
}
// Limit input numbers
function isnumber (e) {
if ($ .browser.msie) {
If ((Event.keycode> 47) && (Event.keycode <58)) ||
(Event.Keycode == 8)) {
Return true;
} Else {
Return false;
}
} Else {
if ((E.Which> 47) && (E.Which <58)) ||
(e.which == 8)) {) {
Return true;
} Else {
Return false;
}
}
}
// String length cut
Function Cutstr (Str, Len) {
var test;
var iCount = 0;
var Patrn =/[^/X00-/XFF]/;
var strre = "";;
for (var I = 0; I <str.Length; i ++) {
if (iCount <Len -1) {
temp = str.substr (i, 1);
if (patrn.exec (temp) == null) {
icount = icount + 1;
} Else {
icount = icount + 2;
}
strre += test;
} Else {
Break
}
}
Return Strre + "...";;
}
// Get the domain name host
Function Gethost (URL) {
var host = "null";
ifof url == "underfined" || null == url) {
url = window.location.href;
}
var regex =/^/w+/:////// ////////////////////////////////kshmnalous
varming = url.match (regex);
if (Typeof Match! = "UNDEFINED" && NULL! = MATCH) {
host = match [1];
}
Return host;
}
// Determine whether a value is in the area
// Rang = 1 indicates the positive integer [0,2147483647] 2 indicates Float [0,3.4028235e38]
// Return = 'Empty' means that the input is empty,
Function Israng (Str, Rang) {
If (Typeof Str == "Number") {{
var num = number (str);
// Determine whether it is in the range of the positive integer
if (right == 1) {
if (testplusdigit (num) == "yes") {{
if (num> = 0 && num <= 2147483647) {{
Return "is_int";
} Else {
Return "is_not_int_rang";
}
} Else {
Return "is_not_int";
}
} else if (rang == 2) {{
if (testpriceformat (num) == "yes") {{
if (num> = 0 && num <= 3.4028235e38) {
Return "is_float";
} Else {
Return "is_not_float_rang";
}
} Else {
Return "is_not_float";
}
} Else {
RETURN "RANG_IS_NOT_RIGHT";
}
} Else {
Return "is_not_number";
}
}