How to do numeric validation using JQuery. I have to validate my price field using JQuery. any body knows please share your knowledge with me :(
If your looking for form validation, you can look into the validation plugin: http://docs.jquery.com/Plugins/Validation
However if you just want some sample code, it could be as simple as this:
$(function() {
$('ref-to-input').blur(function() {
if($(this).val().match(/[^\d]/)) {
// invalid chars detected
}
});
});
you could also filter your input to only allow numeric characters:
$(function() {
$('ref-to-input').keyup(function() {
$(this).val($(this).val().replace(/[^\d]/, ''));
});
});
Edit: don't forget to always use server side checking
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With