Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-19-2005, 11:58 AM   #1 (permalink)
mrasla
Junior Member
 
Join Date: Aug 2005
Posts: 27
Default Form input validation

Hi,
I need to know how to parse a String in PHP in my form.
For example when a use enters his/her name, I want to check that the user only entered alphabetical characters.

thanks
mrasla is offline   Reply With Quote
Sponsored Links
Old 09-19-2005, 06:39 PM   #2 (permalink)
taylor
Junior Member
 
Join Date: Aug 2005
Posts: 28
Default

Most times numbers are not part of a name. But apostrophes, spaces, dashes, periods and commas might or can be.

PHP variable names must begin with "$" so this eaxample may help:
PHP Code:
for($i=0;$i<strlen($name);$i++)
{
   if((
$char[i]<'a' ||$char[i]>'z')&&($char[i]<'A' ||$char[i]>'Z'))
   {
   return 
FALSE;
   }
  return 
TRUE;

With PHP you could also use a regular expression engine that would allow the above to be done without the loop.

cheers
taylor is offline   Reply With Quote
Old 06-23-2006, 04:14 AM   #3 (permalink)
mehedym
Junior Member
 
Join Date: Jun 2006
Posts: 3
Default Re: Form input validation

HI.

can u explain how does the code works. i am little confused
mehedym is offline   Reply With Quote
Old 06-23-2006, 03:57 PM   #4 (permalink)
etono
Moderator
 
Join Date: May 2006
Posts: 86
Default Re: Form input validation

You can use the ctype_alpha function to achieve the same results.
PHP Code:
<?php
if( ctype_alpha$name ) ) {
    echo 
"$name contains only alpha characters.";
} else {
    echo 
"$name does not consist of only alpha characters.";
}
?>
__________________
Jeremy Moseley
My Links: Design Related Blog | Personal Website | Portfolio
etono is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 04:44 AM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums