I'm trying to create perfect number validation using JQuery. I saw This website ealier, but if you type some of the Not allowed numbers, then it still show as valid number.
How I can create this JQuery validation for example numbers ONLY from Allowed list?
Allowed:
- 1
- 1.2454554
- 0.25325
- 654664
Not allowed:
- 0.
- 05
- 0999
- 0.435.53
- 0,53
- dfgdfhjghfs
Code:
<script>
$('#ch_rate').keyup(function(){
var rate_input = $(this).val();
var rate_regexp = new RegExp('^\d+(\.\d+)*$');
if (rate_input.replace(/ /g,'').length > 1 && rate_input.charAt(0) == 0 && rate_input.indexOf('.') == 0 || !rate_regexp.test(rate_input)) {
// invalid
}
});
</script>
Input:
<input id='ch_rate' type='text' pattern='[0-9\.]'/>