/*** 2010-7-13*彼はchen* love* jsさまざまなフォームデータ 検証*//******************************************************************************************************************************************************************************* ****************************************************************************************************************************************************************つ****************************************************************************************************************************************************************つ****************************************************************************************************************************************************************つ****************************************************************************************************************************************************************つ****************************************************************************************************************************************************************つ****************************************************************************************************************************************************************つ********************************************************************************************************************************Kデジタルの検証********************************************************************************************************************************************************************************************************入力文字列がすべて数字であるかどうか*入力:str文字列* return:trueまたはflase; trueはnumber*/function checknum(str){return str.match(// d/)== null;}/***入力文字列が10進数であるかどうかを確認します* input:str string* return:trueまたはflase; trueは10進数で表されます*/function checkdecimal(str){if(str.match(/^ - ?/d+(/./ d+)?$/g)== null){return false; } else {return true; }}/***入力文字列が整数データであるかどうかを確認*入力:str文字列* return:trueまたはflase; trueは10進数で表されます */function checkinteger(str){if(str.match(/^[ - +]?/d *$/)== null){return false; } else {return true; }/***************************************************************************** // ****************************************************************************************************************************************************************************************************************************************************という文字*入力:str string* return:trueまたはflase; trueは、すべての文字に漢字が含まれていないことを意味します*/function checkstr(str){if(/x00-/x00-/xff]/g.test(str)){return false; } else {return true; }}/***入力文字列に漢字が含まれているかどうかを確認*入力:str string* return:trueまたはflase; trueは、漢字*/function checkchinese(str){if(escase(str).indexof( "%u")!= -1){return true; } else {return false; }}/***入力されたメールボックス形式が正しいかどうかを確認* ENTER:str string* return:trueまたはflase; trueは形式が正しい*/function checkemail(str){if(str.match(/[a-za-z0-9 _-]+[@](/s*)(net | com | cn | org | cc | tv | [0-9] {1,3})(/s*)/g){nullを返す; } else {return true; }}/***入力された携帯電話番号が正しいかどうかを確認します* Enter:str string* return:trueまたはflase; trueは形式が正しい*/function checkmobilephone(str){if(str.match(/^(?:13/d | 15 [89]) - ?/d {5}(/d {3} |/*{3})$/)== null){return false; } else {return true; }}/***入力された固定電話番号が正しいかどうかを確認* ENTER:str string* return:trueまたはflase; trueは、形式が正しい*/function checktelephone(str){if(str.match(/^(([0/+]/d {2,3} - )?(0/d {2,3}) - )(/d {7,8})(/d {7,8})( - (/d {3、}))? } else {return true; }}/*** qqの形式が正しいかどうかを確認* Enter:str string* return:trueまたはflase; trueは形式が正しい*/function checkqq(str){if(str.match(/^/d {5,10} $/)== null){return false; } else {return true; }}/***入力されたID番号が正しいかどうかを確認* ENTER:str string* return:trueまたはflase; trueは形式が正しい*/function checkcard(str){// 15-digit id card正規表現var arg1 =/^[1-9]/d {7}(0/d)|(1 [0-2]))(([0 | 1 | 2]/d)| 3 [0-1])/d {3} $/; // 18桁のIDカード正規表現var arg2 =/^[1-9]/d {5} [1-9]/d {3}(0/d)|(1 [0-2] |(1 [0 | 1 | 2]/d)))))))))))))) if(str.match(arg1)== null && str.match(arg2)== null){return false; } else {return true; }}/***入力されたIPアドレスが正しいかどうかを確認* ENTER:str string* return:trueまたはflase; trueは正しい形式*/function checkip(str){var arg = /^ (/d {1,2 }|1/d/d|2 [0-4]/d|25 [0-5]) 。(/d {1,2} | 1/d/d | 2 [0-4]/d | 25 [0-5])/。(/d {1,2} | 1/d/d | 2 [0-4]/d | 25 [0-5])$/; if(str.match(arg)== null){return false; } else {return true; }}/***入力URLアドレスが正しいかどうかを確認*入力:str string* return:trueまたはflase; trueは形式が正しい*/function checkurl(str){if(str.match(/(http [s]]?| ftp):: ///// [^/// }}/***入力文字に特殊文字があるかどうかを確認*入力:str string* return:trueまたはflase; Trueは、情報を登録するときに主に検証に使用される特殊文字*/function CheckQuote(str){var items( "〜"、 "` "、" items.push( ":"、 ";"、 "'"、 "|"、 "//"、 "<"、 ">"、 "?"、 "?"、 "<<"、 ">>" || "、" // "); items.push( "admin"、 "Administrators"、 "Administrator"、 "Administrator"、 "Administrator"、 "System Administrator"); items.push( "select"、 "delete"、 "update"、 "insert"、 "create"、 "drop"、 "alter"、 "trancate"); str = str.tolowercase(); for(var i = 0; i <items.length; i ++){if(str.indexof(item [i])> = 0){return true; }} return false;}/*********************************************************** // **********************************************************************************************************************************************************************************************************************入力:str string* return:trueまたはflase; trueは形式が正しい*注:中国の日付形式をここで確認できません*短い日付(2007-06-05)*/function checkdate(str){// varを確認するvalue = str.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-9] | 0?[1-9])$)|(^((1 [8-9]/d {2})|(([2-9]/d {3}))( - )(0?2)( - )(2)(2 [0-8] | [0-9] | 0? [2468] [048] 00)( - )(0?2)( - )(29)$)|(^([2468] [048] [048] [048] 00)( - )(0?2)( - )(29)$)|(^([2468] [048] 00)( - )(0? ([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] [048])( - )(0?2)( - )(29)$)|(^([1] [89] [13579] [26])( - )(0?2)( - )(29)$)|(^([2-9] [0-9] [13579] [26])( - )(0?2)( - )(29)$)/)/); var value = str.match(/^(/d {1,4})( - | //)(/d {1,2})/2(/d {1,2})$/); if(value == null){return false; } else {var date = new Date(value [1]、value [3] -1、value [4]); return(date.get.lyear()== value [1] &&(date.getMonth() + 1)== value [3] && date.getDate()== value [4]); }}/***時間形式が正しいかどうかを確認します* enter:str string* return:trueまたはflase; trueは形式が正しい *検証時間(10:57:10) */function checktime(str){var value = str.match(/^(/d {1,2})(:)?(/d {1,2})/2(/d {1,2})$/)if(value == null){return fals; } else {if(value [1]> 24 || value [3]> 60 || value [4]> 60){return false} else {return true; }}}/***完全な日付時間形式が正しいかどうかを確認します* enter:str string* return:trueまたはflase; trueは形式が正しい *(2007-06-05 10:57:10) */function checkfulltime(// var value = str.match(/d {1,4})( - | //)(/d {1,2})/2(/d {1,2}) (/d {1,2}):(/d {1,2}):(/d {1,2})$/); var value = str.match(/^(?:19 | 20)[0-9] [0-9] - (?:(?:0 [1-9])|(?:1 [0-2] [1-9])|(?:[1-3] [0-1])) (?:(?:[0-2] [0-3])|(?:[0-1] [0-9])):[0-5] [0-9]:[0-5] [0-9] $/); if(value == null){return false; } else {// var date = new Date(checkfulltime [1]、checkfulltime [3] -1、checkfulltime [4]、checkfulltime [5]、checkfulltime [6]、checkfulltime [7]); // return(date.get.fullyear()== value [1] &&(date.getmonth() + 1)== value [3] && date.getdate()== value [4] && date.gethours()== value [5] && date.getminutes()== value [6]&&date.getSonds()== value [7]); trueを返します。 }/************************************************************************* // *********************************************************************************************************************米dddddddd yymmdd xx p* ddddddd:地域コード* yymmdd:yymmdd:yymmdd:yymmdd:yymmdd:xx:sequential class encoding、sequenting* p:gender、edd number as bemach* <p />* 18-digitエンコーディングルールのIDカード:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD yyyymmdd:生年月日* xxx:シーケンシャルクラスエンコーディングは決定できません、奇数数は男性です* y:検証コード、最初の17桁、この数字値は18桁の重み係数を取得できます。 2,1] *検証ビットy = [1、0、9、8、7、6、5、4、3、2] Y_Pは、フットチェックコードが配置されている検証コード配列の位置です * * */var wi = [7、9、10、8、4、4、2、1、6、3、7、9、10、5、8、4、2、1]; idcardvalidate(idcard){idcard = trim(idcard.replace( / / g、 "")); if(idcard.length == 15){return asaliditybrithby15Idcard(idcard); } else if(idcard.length == 18){var a_idcard = idcard.split( ""); // idカードarrayを取得するif(isvaliditybrithby18idcard(idcard)&& istruevalidatecodeby18idcard(a_idcard)){return true; } else {return false; }} else {return false; }}/*** ID番号が18桁の場合、最後の確認ビットが正しいかどうかを判断します* @param a_idcard id number* @return*/function istruevalidatecodeby18idcard(a_idcard){var sum = 0; //加重合計変数を宣言する場合は、(a_idcard [17] .tolowercase()== 'x'){a_idcard [17] = 10; //検証コードを10で10で10に置き換えます} for合計11; //検証コードを取得する場所if(a_idcard [17] == validecode [valcodeposition]){return true; } else {return false; }}/*** IDカードで男性か女性かを決定します* @param idcard 15/18桁のIDカード番号* @return 'female'-female、 'Male'-male*/function maleorfemalbyidcard(idcard){idcard = triam(idcard.replace(//g、 ");/process the id number。文字間のスペースを含む。 if(idcard.length == 15){if(idcard.substring(14、15)%2 == 0){return 'female'; } else {return 'male'; }} else if(idcard.length == 18){if(idcard.substring(14、17)%2 == 0){return 'female'; } else {return 'male'; }} else {return null; }}/*** 18桁のID番号の誕生日が有効な誕生日であることを確認します* @param idcard 18桁の本ID string* @return*/function isvaliditybrithby18idcard(idcard18){var year = idcard18.substring(6、10); var month = idcard18.substring(10、12); var day = idcard18.substring(12、14); var temp_date = new Date(year、parsefloat(month)-1、parsefloat(day)); //ここでgetFullyear()を使用して、1年を取得してミレニアムバグの問題を回避します。 } else {return true; }}/*** 15桁のIDカード番号の誕生日が有効な誕生日であるかどうかを確認* @param idcard15 15 digit bookカードstring* @return*/function isvaliditybrithby15idcard(idcard15){var year = idcard15.substring(6、8); var month = idcard15.substring(8、10); var day = idcard15.substring(10、12); var temp_date = new Date(year、parsefloat(month)-1、parsefloat(day)); //古いIDカードの年齢については、ミレニアムバグの問題を考慮してgetyear()メソッドを使用する必要はありません。 } else {return true; }} //文字列ヘッドとテールスペース機能トリム(str){return str.replace(/(^/s*)|(/s*$)/g、 "");}上記は、この記事のコンテンツ全体です。 JavaScriptの詳細については、「JavaScriptリファレンスチュートリアル」と「JavaScriptコードスタイルガイド」をご覧ください。また、誰もがwulin.comをもっとサポートすることを願っています。