I want to make the textbox allow only three digits and three decimals.For example 999.999.similarly it doesnt allow any characters like a,b,/,etc.How can I do with the Jquery?
views:
352answers:
3
+1
A:
Have you looked at the jQuery.validate plugin?
$('#formid').validate({
rules: {
fieldname: {
required:function(element) {
return /^\s*[0-9]{,3}(?:\.[0-9]{1,3})?\s*$/.test(element.value);
}
}
}
});
EDIT: admittedly I didn't test the regex and merely wanted to demonstrate how it works. Updated regex as per nickf's suggestion, thanks.
barkmadley
2009-11-02 10:33:44
this doesn't even work. any value with any numbers or a dot will pass the validation: `"1234.5678", "hello."`, etc
nickf
2009-11-02 12:37:41
suggested change: `/^\s*[0-9]{,3}(?:\.[0-9]{1,3})?\s*$/`
nickf
2009-11-02 12:39:33