I am currently working on prepending using jQuery. Here in the text field if the user enters a 2 digit number in a text field, when he clicks outside it automatically should add 0
before the text — for example if the user types 12
and he focuses out the value should be 012
With the current code I am checking how many letters he entered but I am confused how to give this append or concatenation.
With this code I am validating the text field using jquery validator
txt_CC:{
required: true,
number:true,
maxlength:3
},
Here is my jquery code
$('#txt_CC').on('change',function(e){
if($('#txt_CC').val().length > 2){
$('.cc_field').val() + '0';
}else{
alert("Sorry not eligble");
}
});
Here is my input field.
<input type="text" class="cc_field" placeholder="Country Code"
id="txt_CC" maxlength="3" name="txt_CC" />