Currently i am working on jquery validation. here I have two text field where the user can enter only number if user trying to enter by mistaken alphabets it should say digit only.
With my current code this is working perfectly fine but the text is not clearing properly.
here is the jquery code
$('.txt_CC').on('change',function(e){
var len = $('#txt_CC').val().length;
if(len == 1){
$('.cc_field').val( '00' + $('.cc_field').val());
}else if(len == 2){
$('.cc_field').val('0'+ $('.cc_field').val() );
}else if(len == 3){
}
});
$('.txt_CC').keypress(function(e){
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$('.txt_CC').val('');
alert("Digit only");
}
});
Please suggest me whether my code is correct
Here is the fiddle link for the html
Thanks in advance