validation file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kamsmartx
Forum Newbie
Posts: 21
Joined: Mon Apr 21, 2008 10:03 am

validation file

Post by kamsmartx »

hi all
i need to make file to valid the input text
e.g:-
when i enter on the textfield for name we must enter char from (a-z) other wise error
???
how
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: validation file

Post by aceconcepts »

Code: Select all

preg_match("/[A-Za-z]*/", $string);
kamsmartx
Forum Newbie
Posts: 21
Joined: Mon Apr 21, 2008 10:03 am

Re: validation file

Post by kamsmartx »

ok
but u canoot tell me where i put it
my code is

Code: Select all

label>
      <input type="text" name="Time" />
    </label>
 
where i put your code
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: validation file

Post by aceconcepts »

Basically the line of code I posted compares a given string with the pattern "/[A-Za-z]*/"

This code should go in your validation section of code - once the form has been submitted.

Have you created a form?
kamsmartx
Forum Newbie
Posts: 21
Joined: Mon Apr 21, 2008 10:03 am

Re: validation file

Post by kamsmartx »

this file i wont to valid it

Code: Select all

<input type="text" name="FirstName" />
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: validation file

Post by aceconcepts »

I know you want to validate an input field's value.

What you need to do is create a form:

Code: Select all

 
<form method="post">
<input type="text" name="FirstName" />
<input type="submit" name="submit" value="submit" />
</form>
 
A form is needed to post/submit the form fields.
kamsmartx
Forum Newbie
Posts: 21
Joined: Mon Apr 21, 2008 10:03 am

Re: validation file

Post by kamsmartx »

ok
this is the form
but where the valid of text
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: validation file

Post by aceconcepts »

You need to determine whether the form has been submitted:

Code: Select all

 
if(isset($_POST['submit']))
{
   //preg_match("/[A-Za-z]*/", $_POST['FirstName']); goes here
}
 
kamsmartx
Forum Newbie
Posts: 21
Joined: Mon Apr 21, 2008 10:03 am

Re: validation file

Post by kamsmartx »

???
i canot understand
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: validation file

Post by aceconcepts »

People don't usually just spew out the code - try learning more about basic html and logic.

Anyway, here is one rather crude way of doing what you want:

Code: Select all

 
<?
if(isset($_POST['submit']))
{
   if(!empty($_POST['FirstName']))
   {
      if(!preg_match("/[A-Za-z]*/", $_POST['FirstName']))
      {
         //error
      }
   }
}
?>
 
<form method="post">
<input type="text" name="FirstName" />
<input type="submit" name="submit" value="submit" />
</form>
 
Post Reply