I have a mobile number field.I need to implement the validation that if user enter a number continuously for 5 times it should alert as error.
For example if user enters something like 11111345 or 22222777 it should alert an error.
I have a mobile number field.I need to implement the validation that if user enter a number continuously for 5 times it should alert as error.
For example if user enters something like 11111345 or 22222777 it should alert an error.
You can use global variables for that purpose. I don't know if the code works, but you may catch the logic.
var window.inputcontrol;
var window.count=0;
$("#yourInput").keyup(function (){
var inputtedNumber;
//get the last character
inputtedNumber = $("#yourInput").val().slice(-1);
if (inputtedNumber===inputcontrol){
//if inputted value is the same holded value
count= count+1;
} else {
//if inputted value is not the same with holded value, reset counter
inputcontrol=inputtedNumber;
count=0;
}
if (count===5){
alert("your alert");
}
});
Use this Regex to match exactly 5 consecutive numbers ...
/(^|(.)(?!\2))(\d)\3{4}(?!\3)/