Forum Dictionary / Programming / 網頁/網站程式 / JavaScript /

JS 正規化表示法做資料驗證

New Subject
Random
Previous
Next
|
JS 正規化表示法做資料驗證

身份證字號正規化驗證
  1. function checkID(string) {
  2.   re = /^[A-Z]\d{9}$/;
  3.   if (re.test(string)) return true;
  4.   }

信用卡號正規化驗證
  1. function checkCreditCard(string) {
  2.   re = /^\d{4}-\d{4}-\d{4}-\d{4}$/;
  3.   if (re.test(string)) return true;
  4.  }

英文名稱正規化驗證
  1. function checkEnglishName(string) {
  2.   re1 = /^[A-Za-z\-]+\s+[A-Za-z\-]+$/;
  3.   re2 = /^[A-Za-z\-]+\s+[A-Za-z\-]+\s+[A-Za-z\-]+$/;
  4.   if (re1.test(string) || re2.test(string)) return true;
  5.   } 

Email 正規化驗證
  1. function checkEmail(string) {
  2.   re = [url=]/^.+@.+\..{2,3}$/[/url];
  3.   if (re.test(string))return true;
  4.   }

  • Keywords : string, return, function, 正規化驗證, checkID, checkEmail, checkCreditCard, Email
0 0
2010-05-08T04:07:00+0000


  • Now, you can post comments by Facebook Account when your Yampiz account was logout or unvariable. whatever, we suggest to post comment by Yampiz Account to get more bounds to join new events of Heyxu
Comment
 
Verify