954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ID number validation

i have ID numbers that i want to enter it into my database using filling form by user. so i need to validate this number format. number format should be like this. first 9 numbers and after nine numbers it must have a letter V. (123456789V) i need to validate this number format when entering to form. i use array and chk the array for number format. bt its too long coding format.. anyone can give me a short code.please any one can help mee..

Kadafiz
Light Poster
34 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 


Hi Kadafiz. Try this idea.

1. You can restrict the "userID text box" to make it accept only integers (0-9) using javascript. here's the code.

<HTML>
   <HEAD>
   <SCRIPT language=Javascript>
      
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
    
   </SCRIPT>
   </HEAD>
   <BODY>
      <INPUT onkeypress="return isNumberKey(event)" type="text" name="userID" maxlength="9">
   </BODY>
</HTML>

2. Restrict again your "userID textbox" to make it allow 9 digits only using maxlength
3. Now just define the last character which is the letter V. someting like

<?php

$id = $_POST['userID']."V";

?>


So you can now sure that the user will input only the required ID format.

I hope that could help you.

lyrico
Junior Poster in Training
94 posts since Dec 2010
Reputation Points: 33
Solved Threads: 15
 

hey thnku very muh....bt user need to enter letter V nt by the system... thats must.. plz can u do it..

Kadafiz
Light Poster
34 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

You could manipulate string to see if it contains letter 'V' at 10th position (9th if you consider that the string starts with index 0, 1... and so on). One way to achieve your goal is,

$num = "123456789V"; 

if(strlen($num) == 10){
  echo "OK. length is OK."; //assuming that you would want to know if the length is 10

 if(strpos($num, "V") == 9){ //now checking if "V" is at 9th position. since strpos     returns index, 10th position is at 9th index. 
   echo "V is at 9th position";
   echo "now checking if the rest is all numbers";
   $numb2 = substr($num, 0, 9); //here, its creating a substring from $num string. the new string would contain characters starting at index 0 and then upto 8th index. 9 here means that the length of the new string should be 9. (from 0 - 8 it is 9)
  if(is_numeric($numb2)==true){ //use is numeric method to see if the new string contains all numbers
    echo "the rest are all numbers";
  }
 }
}



hope this helps.

kekkaishi
Junior Poster
164 posts since Oct 2009
Reputation Points: 28
Solved Threads: 37
 


I can do that but it needs a long coding. Ahm just let me browse the internet for it, and see what I can got. hehehe

lyrico
Junior Poster in Training
94 posts since Dec 2010
Reputation Points: 33
Solved Threads: 15
 


Kekkaishi code works fine. ^^, try it.

lyrico
Junior Poster in Training
94 posts since Dec 2010
Reputation Points: 33
Solved Threads: 15
 
// code for your form
<input type='text' name='userid' maxlenght='10'>

//code for php
<?php
 
 $userid = $_POST['userid'];
 $userid1 = substr($userid,0,9);
 $userid2 = substr($userid,9,1);

 if(is_numeric($userid1)==true && $userid2=="V")
 {
   echo "correct userid format";
 }

 else
 {
   echo "User ID does not meet the required format.";
 }

?>
lyrico
Junior Poster in Training
94 posts since Dec 2010
Reputation Points: 33
Solved Threads: 15
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: