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..

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.

   <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;
      <INPUT onkeypress="return isNumberKey(event)" type="text" name="userID" maxlength="9">

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


$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.

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

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.

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

Kekkaishi code works fine. ^^, try it.

// code for your form
<input type='text' name='userid' maxlenght='10'>

//code for 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";

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