Page 1 of 1
validation file
Posted: Mon Apr 21, 2008 10:27 am
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
Re: validation file
Posted: Mon Apr 21, 2008 10:48 am
by aceconcepts
Code: Select all
preg_match("/[A-Za-z]*/", $string);
Re: validation file
Posted: Mon Apr 21, 2008 11:03 am
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
Re: validation file
Posted: Mon Apr 21, 2008 11:11 am
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?
Re: validation file
Posted: Mon Apr 21, 2008 11:16 am
by kamsmartx
this file i wont to valid it
Code: Select all
<input type="text" name="FirstName" />
Re: validation file
Posted: Mon Apr 21, 2008 11:22 am
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.
Re: validation file
Posted: Mon Apr 21, 2008 11:57 am
by kamsmartx
ok
this is the form
but where the valid of text
Re: validation file
Posted: Mon Apr 21, 2008 12:08 pm
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
}
Re: validation file
Posted: Mon Apr 21, 2008 12:45 pm
by kamsmartx
???
i canot understand
Re: validation file
Posted: Mon Apr 21, 2008 12:50 pm
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>