JavaScript验证字符串只能包含数字或者英文字符的代码实例

2016-02-04 0 191
JavaScript验证字符串只能包含数字或者英文字符的代码实例

验证字符串只能包含数字或者英文字符的代码实例:
本章节分享一段代码实例,它实现了验证字符串内容是否只包含英文字符或者数字。
代码实例如下:

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));

遇见资源网 js/jquery JavaScript验证字符串只能包含数字或者英文字符的代码实例 http://www.ox520.com/11316.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务