HTML form JavaScript verification universal mode (Favorites)

xiaoxiao2021-03-06  103

HTML form JavaScript verification universal mode

The circulating main code is as follows:

/ **************************** Author: Zhao-year peak * format NULL is empty judgment NUM digital AB letter CHS Chinese character Bit bit phone format Email email format http format * / function check_null (check_obj) {var str = '; for (i = 0; i

function check_num (check_obj) {var i, j, strTemp; // abcdefghijklmnopqrstuvwxyz strTemp = "0123456789"; if (check_obj.length == 0) return false; for (i = 0; i

function check_ab (check_obj) {var i, j, strTemp; strTemp = "abcdefghijklmnopqrstuvwxyz"; if (check_obj.length == 0) return false; for (i = 0; i

Function check_chs (check_obj) {if (check_obj.search (/ [^ / x00- / x80] /)> = 0) {return true;} else {returnaf false;}}

function check_bit (check_obj, bit_obj) {arry_str = bit_obj.split ( '_'); var obj_length = check_obj.length; switch (arry_str [2]) {case ">": if (obj_length> arry_str [1]) {return True;} Break; Case "<": IF (obj_length =": if (obj_length> = arry_str [1]) {Return True;} Break; Case "<=": IF (obj_length <= arry_str [1]) {return true;} Break;} returnaf false;} function check_phone (check_obj) {if (check_obj.search (/ [0-9] {4} / [0-9] * /)> = 0) {Return True;} else {return false;}}

Function check_email (check_obj) {if (check_obj.search (/ ^ [/ w -] @ [/ w -] /. [A-ZA-Z0-9] {2,} $ /)> = 0) { Return True;} else {return false;}}

Function check_http (check_obj) {if (check_obj.search (/ ^ https?: (/ w | -) /.) / w //? $ / i)> = 0) {Return True;} else {return False;}}

/ ************************************************** * Function Purpose: Automatic Detection Form * Parameters: Form_Name The FORM Object Name * INPUT_ARRY To detect the first location of the INPUT control target group * Input_arry parameter array is the name of the * control, the second location is if an error * To display Error information string, third bit * set the detection range flag, if the multi-flag can * use, separate.

For example, 'num, null' cannot be empty, * and can only be digital * / function auto_check_form (form_name, input_arry) {for ('ok'); alert_flag = 0; arry_str = input_arry [Num] [2] .split (','); for (var es_num in arry_str) {switch (arry_str [es_num]) {case "null": if (Check_null (INPUT_ARRY [NUM] [0] .Value) == True) {Alert_flag = 1;} Break; Case "NUM": if (Check_NUM (INPUT_ARRY [NUM] [0] .Value) == false) {alert_flag = 1;} Break case "ab": IF (Check_ab (Input_arry [NUM ] [0] .Value) == false) {alert_flag = 1;} Break; Case "CHS": IF (Check_CHS (INPUT_ARRY [NUM] [0] .Value) == false) {alert_flag = 1;} Break; Case "phone": if (Check_Phone (INPUT_ARRY [NUM] [0] .Value) == false) {alert_flag = 1;} Break; CASE "email": if (check_email (INPUT_ARRY [NUM] [0] .Value) === false) {alert_flag = 1;} Break; Case "http": if (Check_HTTP (Input_arry [Num] [0] .value) == false) {alert_flag = 1;} Break; default:} IF (arry_str [es_num] .Search (/ bit _ * /)> = 0) {if (Check_bit (INPUT_ARRY [NUM] [0] .Value, arry_str [ ES_NUM]) == false) {alert_flag = 1;}}} f (alert_flag ==

1) {Alert (INPUT_ARRY [NUM] [1]); return 0;}} form_name.submit ();} Note: Checkspace function is empty

The HTML square calls more judgment support through array and control object name, comparison mode, such as the third parameter of the second parameter in the middle of the number of the second parameter, can be written:

οnclick = "Auto_CHECK_FORM (TEST1, [[[Text_1, 'can't be empty and can only be numbers', 'null, num'], [text_2, 'can't be empty can only be alphabetical', 'null, ab'], [text_3 , 'Can't be less than 9 bits',' NULL, NUM, BIT_9_> '], [Text_4,' Phone Number Enter Error ',' Null, Phone, Bit_13 _ <= '], [TEXT_5, "Please enter Chinese characters to make a name', 'null, chs, bits_6 _>']]); ">"

NULL, PhONE, BIT_13 _ <= These are all matching characters.

The above is just an example program. This version has been corrected BUG is now a full version.

Posted on August 12, 2004 12:54 PM

Feedback This article has no comments. Post CommentTitle

转载请注明原文地址:https://www.9cbs.com/read-100598.html

New Post(0)