admin管理员组文章数量:1395159
I want to validate my username input box that does not allows any number or special characters inside. My Html
<div class="form-group">
<input type="text" name="username" id="display_name" class="form-control input-lg"
placeholder="User Name" tabindex="3">
</div>
Javascript Validation
username: {
required: true,
minlength: 5,
maxlength: 15,
remote: "ajax_val/val_username.php",
notNumber: true
},
I want to validate my username input box that does not allows any number or special characters inside. My Html
<div class="form-group">
<input type="text" name="username" id="display_name" class="form-control input-lg"
placeholder="User Name" tabindex="3">
</div>
Javascript Validation
username: {
required: true,
minlength: 5,
maxlength: 15,
remote: "ajax_val/val_username.php",
notNumber: true
},
Share
Improve this question
edited Apr 20, 2015 at 18:58
entropid
6,2395 gold badges35 silver badges45 bronze badges
asked Apr 20, 2015 at 18:20
user4410715user4410715
1
- 1 What's your question? – Dave Commented Apr 20, 2015 at 18:23
2 Answers
Reset to default 6You can use this regex:
var regex = /^[a-zA-Z]*$/;
DEMO
and if you dont want to use Regex then here is one approach:
function allowLetters(e, t) {
try {
if (window.event) {
var charCode = window.event.keyCode;
}
else if (e) {
var charCode = e.which;
}
else { return true; }
return charCode > 64 && charCode < 91 || charCode > 96 && charCode < 123;
}
catch (err) {
alert(err.Description);
}
}
Here is one approach for HTML5 pattern attribute:
<form>
<input type='text' pattern='[A-Za-z\\s]*'/>
</form>
I would take a look at regex something like [A-Za-z]+
.
This may be helpful: (or any other guide on RegExp's on the internet)
https://developer.mozilla/en/docs/Web/JavaScript/Guide/Regular_Expressions
本文标签: javascriptInput validation for only alphabetical charactersStack Overflow
版权声明:本文标题:javascript - Input validation for only alphabetical characters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744733216a2622169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论