[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to add code for contact number?

Posted on 2013-06-22
10
Medium Priority
?
442 Views
Last Modified: 2013-06-28
In my website, i have the contact number textbox. Where users are able to give the alphabets also. But, i want users can enter only numbers and length of the number should be 10.

website: www.galliads.com

This is a theme..

Can you guys please suggest em how to make.

Your help is appreciated.
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:SamGarner
ID: 39268759
It's a wordpress site right? Can you just use a plugin? try this and you can custom it to your needs.

http://wordpress.org/plugins/contact/
0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 750 total points
ID: 39268763
You can use javascript for client side validation and php for server side

<script>
            function validate(){
    x=document.myForm.myInput.value;

    if (x >=10)

    {
        alert("Contact must be 10 digit")
        return true

    }

    else if(isNaN(x))

    {
        alert("Contact cant be alphabet")
        return false
    }
    else

    {
        alert("Contact is smaller than required")
        return false
    }

}
    </script>

Open in new window


In php
if (!is_numeric($fieldname))
{
    echo 'Invalid Contact Number.';
}

Open in new window

You can add more code for 10 digit
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 249 total points
ID: 39268764
0
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
LVL 9

Author Comment

by:Vijaya Reddy Pinnapa Reddy
ID: 39268775
Thanks for quick reply

@Sam Garmner: Where can give the conditions using the plugin.

@jagadish: Where can i place that code?
0
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 750 total points
ID: 39268777
0
 
LVL 3

Assisted Solution

by:SamGarner
SamGarner earned 249 total points
ID: 39268781
My bad, I gave you the wrong link...

http://wordpress.org/plugins/contact-form-maker/

They have demos of how to use it and a user manual. Even a forum if you get stuck.

Check the demo and see if this is suitable for your needs. If this isn't right for you have a look through the other plugins.
0
 
LVL 9

Author Comment

by:Vijaya Reddy Pinnapa Reddy
ID: 39268786
I cant link the plugin to the my site. Because, there is no such option for the custom layout.
0
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 750 total points
ID: 39268830
Try developing your custom plugin for validation see here tutorial
http://wordpress.stackexchange.com/questions/63384/how-to-validate-custom-fields-in-custom-post-type
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 252 total points
ID: 39269410
Here is the (current) standard teaching example for validation of USA telephone numbers.  You may be able to tailor this for your needs.

<?php // RAY_phone_numbers.php
error_reporting(E_ALL);

// A FUNCTION TO VALIDATE A USA PHONE NUMBER AND RETURN A NORMALIZED STRING
// MAN PAGE: http://discuss.fogcreek.com/joelonsoftware3/default.asp?cmd=show&ixPost=102667&ixReplies=15
// MAN PAGE: http://www.nanpa.com/number_resource_info/index.html
function strtophone($phone, $format=FALSE, $letters=FALSE, $dlm='-')
{
    if ($letters)
    {
        // TURN INPUT LIKE 1-800-BIG-DOGS
        // INTO INPUT LIKE 1-800-244-3647
        $phone = strtoupper($phone);
        if (preg_match('/[A-Z]/', $phone))
        {
            $phone = strtr
            ( $phone
            , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
            , '22233344455566677778889999'
            )
            ;
        }
    }

    // DISCARD NON-NUMERIC CHARACTERS
    $phone = preg_replace('/[^0-9]/', NULL, $phone);

    // DISCARD A LEADING '1' FROM NUMBERS ENTERED LIKE 1-800-555-1212
    if (substr($phone,0,1) == '1') $phone = substr($phone,1);

    // IF LESS THAN TEN DIGITS, IT IS INVALID
    if (strlen($phone) < 10) return FALSE;

    // IF IT STARTS WITH '0' OR '1' IT IS INVALID, SECOND DIGIT CANNOT BE '9' (YET)
    if (substr($phone,0,1) == '0') return FALSE;
    if (substr($phone,0,1) == '1') return FALSE;
    if (substr($phone,1,1) == '9') return FALSE;

    // ISOLATE THE COMPONENTS OF THE PHONE NUMBER
    $ac = substr($phone,0,3); // AREA
    $ex = substr($phone,3,3); // EXCHANGE
    $nm = substr($phone,6,4); // NUMBER
    $xt = substr($phone,10);  // EXTENSION

    // ADD OTHER TESTS HERE AS MAY BE NEEDED - THESE ARE FOR LOCAL APPS
    if ($ac == '900') return FALSE;
    if ($ac == '976') return FALSE;
    if ($ex == '555') return FALSE;

    // IF NOT FORMATTED
    if (!$format) return $phone;

    // STANDARDIZE THE PRINTABLE FORMAT OF THE PHONE NUMBER LIKE 212-555-1212-1234
    $formatted_phone = $ac . $dlm . $ex . $dlm . $nm;
    if ($xt != '') $formatted_phone .= $dlm . $xt;
    return $formatted_phone;
}



// DEMONSTRATION OF THE FUNCTION IN ACTION.
if (!empty($_GET["p"]))
{
    // VALIDATE PHONE USING FUNCTION ABOVE
    if (!$phone = strtophone($_GET["p"], TRUE))
    {
        // FUNCTION RETURNS FALSE IF PHONE NUMBER IS UNUSABLE
        echo "BOGUS: {$_GET["p"]} ";
    }
    else
    {
        // SHOW THE FORMATTED PHONE
        echo "VALID: {$_GET["p"]} == $phone";
    }
}


// PUT UP A FORM TO TEST PHONE NUMBERS
function ph($p)
{
    echo "<br/><a href=\"{$_SERVER['PHP_SELF']}?p=" . urlencode($p) . "\">$p</a>" . PHP_EOL;
}
$form = <<<EOD
<form>
ENTER A PHONE NUMBER:
<input name="p" /><br/>
<input type="submit" />
</form>
TRY SOME OF THESE (CLICK OR COPY AND PASTE):
EOD;
echo $form;
ph('1-800-5551212');
ph('202-537-7560');
ph('202 537 7560');
ph('1-202-537-7560');
ph('(202) 537-7560');
ph('1.202.537.7560');
ph('123456789');
ph('703-356-5300 x2048');
ph('(212) 555-1212');
ph('1 + (212) 555-1212');
ph('1 (292) 226-7000');

Open in new window

Best regards, ~Ray
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39285383
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question