Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<HTML>
 <HEAD>
  <TITLE> </TITLE>

 <script type="text/javascript">
  function formValidation(){
  if (validateAllSame()){
  }
  return false;
  }
  function validateAllSame(){

  var y=document.form1.number.value;
  var x = y.substr(0,2);
  for(int i=0;i<=y.length;i+=2){
  if(y[i] == x){

  }
  return false;
   alert("wrong number");
  }

  return true;
  }

  </script>

 </HEAD>

 <BODY>
  <form name ="form1" action="" onsubmit="return formValidation()">
  Number:<input type="text" name="number" value="">
  <input type="submit" value="Done">
   </form>

 </BODY>
</HTML>






Hi can anyone suggest me what to do with my code..I have tried to write a code that does not allow numbers like 12121212/3434343 etc... Please help me out with the code I am still learning
Posted
Updated 10-Mar-13 7:52am
v3
Comments
Member 9882454 10-Mar-13 14:02pm    
for(int i=2;i<=y.length;i+=2){
if(y.substr([i],2) != x){
return true;
}

}

return false;
alert("wrong number");
}


I just tried replacing this in my for loop..But it still doesnot seem to work..can anyone check please

Hello,

Try following regular expression.

C#
([a-zA-Z0-9]+?)\1+


regards,
 
Share this answer
 
Comments
codegirl24 10-Mar-13 14:54pm    
Hi Prasad,I have the same problem with the code aswell..
Does the regular expression work for numbers and numbers must not be of format 12121212/5656565
Prasad Khandekar 10-Mar-13 15:16pm    
Hi,
It will work with numbers and characters as well. You can use Expresso 3.0 a regular expression tester found here (http://www.ultrapico.com/Expresso.htm) to test various expressions.
codegirl24 10-Mar-13 15:33pm    
thanks a lot prasad :) its working
codegirl24 15-Apr-13 4:23am    
Prasad Khandekar :Hi,
I have used the above regex for same problem i was facing..But the problem is its not allowing numbers like 78890923454 also...meaning 22,88,99 like numbers also are showing error...But phone numbers can have such numbers in sequence right? Ex:98825609978 etc..
Waiting for your reply...Please guide on this.
Prasad Khandekar 15-Apr-13 6:56am    
Hello,

The way you will be checking whether there is a full match could be done as follows

ret = valuetocheck.match(/([a-zA-Z0-9]+?)\1+/gi);
if (ret != null && ret[0] === valuetocheck) alert("ERROR");

For the values you mentioned the first match will be same as the value your checking.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900