Jump to content

Archived

This topic is now archived and is closed to further replies.

Terfanda

Validate a textbox for alphabetic character only

Recommended Posts

Hi All
if some one can tell me how to validate a textbox for example
Name entry to enter only alphabet character

Share this post


Link to post
Share on other sites
if (!eregi("^[a-z]+$",$name)
{die("Invalid name");};

Share this post


Link to post
Share on other sites
[!--quoteo(post=385948:date=Jun 20 2006, 01:47 PM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 01:47 PM) [snapback]385948[/snapback][/div][div class=\'quotemain\'][!--quotec--]
if (!eregi("^[a-z]+$",$name)
{die("Invalid name");};
[/quote]
according to your syntax that you gave i tried to write this
function check_Name($Name,$FamName)
{
if ((!eregi("^[a-z]+$",$Name))||(!eregi("^[a-z]+$",$FamName)))
{
$ans=FALSE;
}
else
{
$ans=TRUE;
}
return $ans;

}


but it is still taking numbers can you tell me if the code up is wrong please thank you

Share this post


Link to post
Share on other sites
Strange it works for me!:[code]<?php

function check_Name($Name, $FamName)
{
    if ((!eregi("^[a-z]+$",$Name)) || (!eregi("^[a-z]+$",$FamName)))
    {
        $ans = FALSE;
    }
    else
    {
        $ans = TRUE;
    }
    return $ans;
}

if(check_Name('j0hn', 'w3lls'))
{
    echo "valid!";
}
else
{
    echo "invalid!";
}

?>[/code]
With numbers it echos invalid, without - john wells - its valid.

How are you checking whether the function returns true or false?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.