Jump to content


Photo

Validate a textbox for alphabetic character only


  • Please log in to reply
3 replies to this topic

#1 Terfanda

Terfanda
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 June 2006 - 10:34 AM

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

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 10:47 AM

if (!eregi("^[a-z]+$",$name)
{die("Invalid name");};
Think you're smarty?

(Gone until 20 to November)

#3 Terfanda

Terfanda
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 June 2006 - 11:28 AM

[!--quoteo(post=385948:date=Jun 20 2006, 01:47 PM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 01:47 PM) View Post[/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

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 June 2006 - 03:32 PM

Strange it works for me!:
<?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!";
}

?>
With numbers it echos invalid, without - john wells - its valid.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users