Hei
Have anyone idea of input mask in jquery For example a field must have three letters followed by 4 numbers. cda1234. If one writes something in the field that does not fit with this must be removed continuously.
Cooked an fast example up, see: http://jsfiddle.net/g8KSg/2/
Checks for non integers for the first 3 characters, and then only accept integers.
Could proberbly be made wiser with regex, but this should give a starting point :)
$('input').keyup(function(e){
var value = $(this).val();
if(value.length <= 3) {
char = value.substring(value.length - 1);
if(!(isNaN(char))) {
var newval = value.substring(0, value.length - 1);
$(this).val(newval);
}
}
if(value.length > 3) {
char = value.substring(value.length - 1);
if(isNaN(char)) {
var newval = value.substring(0, value.length - 1);
$(this).val(newval);
}
}
});
$(document).ready(function() { // put all your jQuery goodness in here. });keyup with blur - but it will only "check" your input when you leave the input field then :)Hi there these links should give you the building blogs on how to achieve this.
First, select the first 3 charectors, here is how: http://www.w3schools.com/jsref/jsref_substring.asp
then check if they are numbers: checking if number entered is a digit in jquery
And so on...