! Removing the handle of the string two ends of spaces If the traditional way is used, it is possible to use the following way // clear left space Function JS_LTRIM (deststr) {if (deststr == null) return "; var pos = 0; var rettstr = new string (deststr); if (retstr.lenght == 0) Return RetStr; while (retstr.substring (pOS, POS 1) == "") POS ; RetStr = retrstr.substring (POS) Return (RETSTR);} // Clear the right space Function JS_RTRIM (DestStr) {if (Deststr == Null) Return "; var retrstr = new string (deststr); var pos = retstr.length; if (POS == 0) RETURN RETSTR; while (POS & Qu "==" ") POS -; RetStr = RetStr.Substring (0, POS); Return (RetStr);} // Clear left and Right space Function JS_TRIM (DESTSTR) {if (deststr == NULL) Return ""; var retrstr = new string (deststr); var pos = retsidength; if (pOS == 0) Return RetStr; RetStr = JS_LTRIM (Retstr ); Ret 'js_rtrim (Retstr); Return Retstr;} Using regular expressions, remove spaces on both sides, simply following the following code string.prototype.trim = function () {Return this.Replace (/ (^ / s *) | (/ s * $) / g, ""); Complete the verification of the following steps, (1). Whether it is a number (2). Whether it is 11 bits (3). If the third bit of the number is 5, 6, 7, 8, and 9 if the regular expression verification , Just the following code function checkmobile1 (form) {if (Form.Mobile.Value> "") {var REG = / 13 [5, 6, 7, 8, 9] / d {8} /; if (Form.Mobile.Value.match (reg) == null) {alert ("Please enter the correct mobile phone number! "); form.mobile.focus (); return false;}} Return true;} From above, you can see that the check mobile phone number only needs to define a varreg = / 13 [5, 6, 7, 8, 9] / D {8} /; mode matching strings can complete the legality check! URL check, condition: must begin with http: // or https: //, the port number must be at 1-65535 In the following code, the following code completes the legitimacy check // OBJ: Data Objects // Dispstr: Failed Tip Content Display String Function CheckurlValid (Obj, Dispstr) {if (Obj == Null) {Alert ("Incoming Object "); Return False;} var str = obj.value; var URLPATERN0 = /^ HTTPS ::
IF (! urlpatern0.test (str)) {Alert (Dispstr "is illegal: must be in 'http:' or 'https:' beginning!"); obj.focus (); returnaf false;} var URLPATERN2 = / ^ https ?: (([A-ZA-Z0-9_-]) (/.)?) * (: / d )? $ / i; if (! urlpaatern2.test (str)) {Alert (Dispstr " The port number must be numbers and should be between 1-65535! "); Obj.focus (); return false;} var URLPATERN1 = / ^ https?: (([A-ZA-Z0-9_-]) ( /.)) * (:/d )? (ket (/ ((((((((((/ ((((((((/ )?=?) (/ /) * * * $ (//?) *) *? / i; if (! urlpaatern1.test (str)) {Alert (Dispstr "is not legal, please check!"); obj.focus (); returnaf false;} var s = "0"; var t = 0; var; var; Re = new regexp (": // d ", "ig"); while ((arr = re.exec (str))! = null) {s = str.substring (regexp.index 1, regexp.lastIndex) ; If (s.Substring (0, 1) == "0") {Alert (DISPSTR "port number does not start with 0!"); Obj.focus (); returnaf false;} t = parseint (s); if (T <1 || T> 65535) {Alert (DISPSTR "port number must be numbers and should be between 1-65535!"); obj.focus (); return false;}} return true;} pair URL Check, it seems to have a lot of code, because it is necessary to give an error message, otherwise only var URLPATERN1 = / ^ https?: (([A-ZA-Z0-9 _-]) (/.)?) * (: / d )? (// (/?)? =? &? [A-ZA-Z0-9 _-] (/?)?) * * $ / i; one sentence Check the URL legality
Author Blog:
http://blog.9cbs.net/blue_jiang/