- Mark as New
- Follow
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hello!
On my form i need to prevent user from typing anything but numbers in a specific field. But i also need to let user delete typed symbols.
For that porpuse i have a function:
function regExp(newsymbol){
var re = /[0-9\b]/;
if(newsymbol.length > 1)
return "";
else if (re.test(newsymbol)){
return newsymbol;
}else{
return "";
}
}
If i type backspace (trying to delete symbol) an "else" part of the expresion works.
So, how to fix my regexp, to let users delete symbols or are there any other ways to check if backspace is pressed (like keyCode and so on)?
Views
Replies
0 Likes
Total Likes