Validate Value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pls guide on following.
1) I want to validate name for a alphabetic value, But if I give space between 2 words then its not supporting..
As example: Name = "PHP Guide"
Then the system says name must be in alphabetic value. Pls find the codd No 1 for more Details :
 
2)I want to validate a phone no for 10 digits. But in this value if I enter "+" or "-" in begining then even 
the system will accept it. So can you pls suggest me what to do to solve the problem ?
As Example : Phone = -984524561. Here "-" will be accepted by the system
Pls find the codd no 2 for more details :
 
COdd no 1 :
function Name_validate()
{
    if($_POST['name']!="")
    {
        $pattern="/^[a-zA-Z]+$/";
        if(preg_match($pattern,$_POST['name']))
         {
           Statements;
         }
        else
        {
            ?>
            <script>
            alert("Name must be in Alphabetic Characters");
            </script>
            <?
        }
    }
    else
    {
    ?>
            <script>
            alert("Pls Enter Name");
            </script>
    <?
            return false;
    }
}
COdd no 2 :
function Phone_validate()
{
     if($_POST['phone']!=="")
    {
        if(!is_numeric($_POST['phone']))
        {
            ?>
            <script>
            alert("Phone No must be in Numeric Characters");
            </script>
            <?
        }
        else if (is_numeric((string)$_POST['phone']) && strlen((string)$_POST['phone']) > 10)
        {
            ?>
            <script>
            alert("Phone No Can't be more than 10 digits");
            </script>
            <?
        }
        else
        {
            statements;
        }
    }
    else
    {
    ?>
            <script>
            alert("Pls Enter Phone No");
            </script>
    <?
            return false;
    }
}


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux