清華大佬耗費三個月吐血整理的幾百G的資源,免費分享!....>>>
驗證字符串只能包含數字或者英文字符的代碼實例:
本章節分享一段代碼實例,它實現了驗證字符串內容是否只包含英文字符或者數字。
代碼實例如下:
function done(input, LengthBegin, LengthEnd) { var pattern = '^[0-9a-zA-z]{' + LengthBegin+ ',' + LengthEnd+ '}$'; var regex = new RegExp(pattern); if (input.match(regex)) { return true; } else { return false; } } var one = "antzone"; var two = "softwhy.com888"; var three = "螞蟻部落softwhy"; console.log(done(one, 2,20)); console.log(done(two, 2, 10)); console.log(done(three,2, 30));