Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  152] [ 7]  / answers: 1 / hits: 149473  / 12 Years ago, mon, october 8, 2012, 12:00:00

I made a regular expression that only accepts letters. I'm not really good in regex, thats why I don't know how to include spaces in my regex.



My HTML:



<input id=input />


My js / jQuery code:



$('#input').on('keyup', function() {
var RegExpression = /^[a-zA-Z]*$/;

if (RegExpression.test($('#input').val())) {

}
else {
$('#input').val();
}
});​

More From » jquery

 Answers
6

use this expression


var RegExpression = /^[a-zA-Zs]*$/;  

Update: 27-April-2023




function validate(){
const regEx1 = /[^a-zA-Zs]+/;
input.value = input.value.replace(regEx1, '');
}

<input id=input type=text onkeyup=return validate();>




[#82706] Friday, October 5, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;