My current code is like this
$('.textBoxClass').bind('keypress', function (e) {
return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) && e.which != 46 && e.which != 43) ? false : true;
});
Use the jQuery keyup event .
You need to check if event.keyCode
is +
and if input field already contains +
.
If yes, you can prevent the event with event.preventDefault()
.
Or you can use some third-part plugin like jqueryvalidation and use a regular expression.
Remember to validate the data serverside because javascript validation can be easily bypassed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.