Copier le code du code comme suit:
String.prototype.trim = function () {
Renvoie ce.replace (/ (^ / s *) | (/ s * $) / g, "");
}
// Vérifiez s'il s'agit du format de date
fonction 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] $) | [8-9] / d {2}) | ([2-9] / d {3}) (-) (0? 2) (-) (2 [0-8] | 1 [0-9] | 0? ) (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) $) | 89] [13579] [26]) (-) (0? 2) (-) (29) $) | (^ 2-9] [0-9] [13579] [26]) (-) (0? 2) (-) (29) $) /););););););););
if (result == null) {
Retourner "non";
}
Retourner "oui";
}
// Cette méthode est cohérente avec l'effet ci-dessus ci-dessus
Fonction isdate2 (datestr) {
var result = datestr.match (/ ^ (/ d {1,4}) (- | //) (/ d {1,2}) / 2 (/ d {1,2});
si (résultat == null)
Retourner "non";
var d = nouvelle date (résultat [1], résultat [3] -1, résultat [4]);
If ((d.getlyear () == Result [1] && (d.getMonth () + 1) == Result [3] && d.getDate () == Result [4]) {) {) {) {{
Retourner "oui";
}
Retourner "non";
}
// déterminer si le caractère d'entrée est chinois
fonction ischinese (str) {
if (str.length! = 0) {{
Reg = / ^ [/ u0391- / uffe5] + $ /;
if (! reg.test (str)) {
// alert ("Désolé, le format de type de la chaîne que vous avez entré est incorrect!"););
Retourner "non";
}
}
Retourner "oui";
}
// juger s'il est vide
Fonction isEmpty (str) {
if (str == null || typeof str == "Underfined" || str.trim () == "") {
Retour Vrai;
} Autre {
Retourne false;
}
}
// Téléphone fixe
Fonction testtelephone (téléphone) {{
Var phone_reg = new regexp (/ ^ ([+] {0,1} / d {3,4} | / d {3,4} -)? / D {7,8} $ /);
if (! phone_reg.test (téléphone)) {{{
Retourner "non";
}
Retourner "oui";
}
//Rabais
Fonction isDiscount (remise) {
var phone_reg = new regexp (/ ^ (0 (/., d {1,2}) | 1 | 1,00 | 1.0);
if (! phone_reg.test (remise)) {
Retourner "non";
}
Retourner "oui";
}
//numéro de téléphone
Fonction testmobile (mobile) {
Var mobile_reg = new regexp (/ ^ 0 {0,1} 1 [0-9] {10} $ /);
if (! mobile_reg.test (mobile)) {
Retourner "non";
}
Retourner "oui";
}
// Le numéro QQ commence à partir de 10000
Fonction testQQQ (qq) {
var qq_reg = new regexp (/ ^ [1-9] [0-9] {4,} $ /);
if (! qq_reg.test (qq)) {
Retourner "non";
}
Retourner "oui";
}
Fonction testmail (e-mail) {
var email_reg = new regexp (/^/w+(@-+.
if (! email_reg.test (email)) {
Retourner "non";
}
Retourner "oui";
}
// L'entier positif sans symboles
Fonction testPlusDigit (chiffre) {
var plusDigit_reg = new regexp (/ ^ / d + $ /);
if (! plusdigit_reg.test (chiffre)) {{
Retourner "non";
}
Retourner "oui";
}
// double prix
Fonction testPriceFormat (str) {
Var priceFormatreg = new regexp (/^/d+(./ d {1,2})? $ /);
if (! PriceFormatreg.Test (str)) {
Retourner "non";
}
Retourner "oui";
}
//Carte d'identité
Fonction testidcard (str) {
Var idcardreg = new Regxp (/ (^ / d {15} $) | (^ / d {17} ([0-9] | x) $) /);
if (! idcardreg.test (str)) {
Retourner "non";
}
Retourner "oui";
}
// format de date 2012-06-19
Fonction testDate (str) {
var dateg = new regexp (/ (^ / d {4} - [0,1] [0-9] - [0-3] [0-9] $) /);
if (! datoreg.test (str)) {
Retourner "non";
}
Retourner "oui";
}
// Comptage des points flottants Opérations précises (plus méthode)
Fonction acadd (arg1, arg2) {{
var r1, r2, m, n;
essayez {r1 = arg1.toString ().
essayez {r2 = arg2.tostring ().
m = math.pow (10, math.max (r1, r2));
n = (r1> = r2)?
Return ((arg1 * m + arg2 * m) / m) .tofixed (n);
}
Nombre.prototype.add = fonction (arg) {
Retour acadd (arg, ceci);
}
// Nombre de points flottants Opérations précises (soustraction)
Fonction AccSub (Arg1, Arg2) {{{
Retour acadd (arg1, -arg2);
}
Number.prototype.Substract = fonction (arg) {
Compte de retour (ceci, arg);
}
// Nombre de points flottants Opérations précises (méthode de multiplication)
Fonction accmul (arg1, arg2)
{{
varm m = 0, s1 = arg1.toString (), s2 = arg2.ToString ();
Try {m + = s1.split (".") [1] .length} catch (e) {}
Essayez {m + = s2.split (".") [1] .length} catch (e) {}
Numéro de retour (s1.replace (".", "") * Numéro (s2.replace (".", "") /Math.pow (10, m)
}
Nombre.prototype.mul = fonction (arg) {
Retour accmul (arg, this);
}
// Nombre de points flottants Opérations précises (divisée par méthode)
Fonction accdiv (arg1, arg2) {{
var t1 = 0, t2 = 0, r1, r2;
essayez {t1 = arg1.toString ().
essayez {t2 = arg2.tostring ().
avec (math) {
R1 = nombre (arg1.toString (). Remplacer (".", ""))
r2 = nombre (arg2.ToString (). Remplacer (".", ""))
Return (r1 / r2) * pow (10, t2-t1);
}
}
Nombre.prototype.div = fonction (arg) {
Retourner accdiv (ceci, arg);
}
// Limiter les numéros d'entrée
fonction isNumber (e) {
if ($ .browser.msie) {
If ((event.KeyCode> 47) && (event.KeyCode <58)) ||
(Event.KeyCode == 8)) {
Retour Vrai;
} Autre {
Retourne false;
}
} Autre {
if ((e.which> 47) && (e.which <58)) ||
(e.which == 8)) {) {
Retour Vrai;
} Autre {
Retourne false;
}
}
}
// coupe de longueur de chaîne
Fonction Cutstr (str, len) {
test var;
var iCount = 0;
var patn = / [^ / x00- / xff] /;
var strre = "" ;;
pour (var i = 0; i <str.length; i ++) {
if (iCount <len -1) {
temp = str.substr (i, 1);
if (patn.exec (temp) == null) {
iCount = iCount + 1;
} Autre {
iCount = iCount + 2;
}
strre + = test;
} Autre {
Casser
}
}
Retour Strre + "..." ;;
}
// Obtenez l'hôte de nom de domaine
Fonction gethost (url) {
var host = "null";
ifof url == "Underfined" || null ==) {
url = window.location.href;
}
var regex = / ^ / w + /: ////// //////////////////////////////////////////////////////////////////// /
varming = url.match (regex);
if (typeof correspond! = "Undefined" && null! = correspond) {
host = correspond [1];
}
Retour hôte;
}
// déterminer si une valeur est dans la région
// Rang = 1 indique que l'entier positif [0,2147483647] 2 indique le flotteur [0,3.4028235e38]
// return = 'vide' signifie que l'entrée est vide,
Fonction israng (str, rang) {
If (typeof str == "nombre") {{{
var num = nombre (str);
// déterminer si c'est dans la plage de l'entier positif
if (droit == 1) {
if (testPlusDigit (num) == "Oui") {{
if (num> = 0 && num <= 2147483647) {{
Return "is_int";
} Autre {
Return "is_not_int_rang";
}
} Autre {
Return "is_not_int";
}
} else if (rang == 2) {{{
if (testPriceFormat (num) == "Oui") {{
if (num> = 0 && num <= 3.4028235e38) {
Return "is_float";
} Autre {
Return "is_not_float_rang";
}
} Autre {
Return "is_not_float";
}
} Autre {
Return "rang_is_not_right";
}
} Autre {
Return "is_not_number";
}
}