1

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.

Smita Ahinave
  • 1,901
  • 7
  • 23
  • 42
Anju
  • 53
  • 5

2 Answers2

0

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");
} 

});
Ece
  • 148
  • 9
0

Use this Regex to match exactly 5 consecutive numbers ...

/(^|(.)(?!\2))(\d)\3{4}(?!\3)/
Satish Kumar sonker
  • 1,250
  • 8
  • 15