0
我要檢查字符串中數字值的出現次數,即該字符串中只允許有2個數字字符。任何人都可以幫我解決這個問題嗎?提前如何使用JavaScript驗證輸入?
我要檢查字符串中數字值的出現次數,即該字符串中只允許有2個數字字符。任何人都可以幫我解決這個問題嗎?提前如何使用JavaScript驗證輸入?
感謝試試這個代碼
var s ="1asds3asa"; // string to check
var t = s.replace(/[^\d]/g,""); // a string with everything but the digits removed
if(t.length>2)
{
alert("Only 2 numbers allowed");
}
thanku SOOO多 – Aaaaa 2011-02-24 12:40:02
見http://stackoverflow.com/search?q=javascript+input+validation – rsp 2011-02-24 12:17:09