How to verify an input field using php
<p>How can I verify that the contact number a user inputs in the contact form is in fact numbers and they are at least 10 numbers? Meaning I want the input field only accept 10 numbers or more and also accept the plus (+) sign. At the moment the php verifies that the all fields are completed and the email correct.</p>

<p>here is the html code:</p>

<pre><code>            &lt;div class="contact-form"&gt;
                &lt;form id="contact-form" action="sendmail.php" method="post" title="Contact Form" role="form"&gt;
                    &lt;div class="col-sm-6"&gt;
                        &lt;div class="form-group"&gt;
                            &lt;label for="contact-name"&gt;Full name&lt;/label&gt;
                            &lt;input type="text" name="name" placeholder="Enter your full name..." class="contact-name" id="contact-name"&gt;
                        &lt;/div&gt;
                        &lt;div class="form-group"&gt;
                            &lt;label for="contact-email"&gt;Email&lt;/label&gt;
                            &lt;input type="text" name="email" placeholder="Enter your email..." class="contact-email" id="contact-email"&gt;
                        &lt;/div&gt;
                        &lt;div class="form-group"&gt;
                            &lt;label for="contact-number"&gt;Contact number&lt;/label&gt;
                            &lt;input type="text" name="number" class="active" id="contact-number" placeholder="Your contact number..."&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="col-sm-6"&gt;
                        &lt;div class="form-group"&gt;
                            &lt;label for="contact-message"&gt;Message&lt;/label&gt;
                            &lt;textarea name="message" placeholder="Your message..." class="contact-message" id="contact-message"&gt;&lt;/textarea&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="col-sm-12 text-center"&gt;
                        &lt;button type="submit" class="btn btn-default sketchFlowPrint" id="submit"&gt;Send&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/form&gt;
          &lt;/div&gt;
</code></pre>

<p>here is the php code:</p>

<pre><code>&lt;?php

// Email address verification
function isEmail($email) {
    return preg_match('|^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$|i', $email);
};

if($_POST) {

    // Enter the email where you want to receive the message
    $emailTo = 'example@gmail.com';

    $clientName = addslashes(trim($_POST['name']));
    $clientEmail = addslashes(trim($_POST['email']));
    $number = addslashes(trim($_POST['number']));
    $message = addslashes(trim($_POST['message']));

    $subject = 'Query from My Domain';

    $sendMessage = 'Hi' . "\n\n";
    $sendMessage .= $message . "\n\n";
    $sendMessage .= 'From: ' . $clientName . "\n";
    $sendMessage .= 'Email: ' . $clientEmail . "\n";
    $sendMessage .= 'Contact number: ' . $number . "\n";

    $array = array();
    $array['nameMessage'] = '';
    $array['emailMessage'] = '';
    $array['numberMessage'] = '';
    $array['messageMessage'] = '';

    if($clientName == '') {
        $array['nameMessage'] = 'Please enter your full name.';
    }
    if(!isEmail($clientEmail)) {
        $array['emailMessage'] = 'Please insert a valid email address.';
    }
    if($number == '') {
        $array['numberMessage'] = 'Please enter a valid contact number.';
    }
    if($message == '') {
        $array['messageMessage'] = 'Please enter your message.';
    }
    if($clientName != '' &amp;&amp; isEmail($clientEmail) &amp;&amp; $message != '') {
    // Send email
    $headers = "From: " . $clientName . ' &lt;' . $clientEmail . '&gt;' . "\r\n";
    $headers .= PHP_EOL;
    $headers .= "MIME-Version: 1.0".PHP_EOL;
    $headers .= "Content-Type: multipart/mixed;".PHP_EOL;
    $headers .= " boundary=\"boundary_sdfsfsdfs345345sfsgs\"";
    mail($emailTo, $subject, $sendMessage, $headers);
    }

    echo json_encode($array);

}   else {
        header ('location: index.html#contact');
}

?&gt;
</code></pre>

<p>here is the jQuery:</p>

<pre><code>// Contact form 
$('.contact-form form').submit(function(e) {
    e.preventDefault();

    var form = $(this);
    var nameLabel = form.find('label[for="contact-name"]');
    var emailLabel = form.find('label[for="contact-email"]');
    var numberLabel = form.find('label[for="contact-number"]');
    var messageLabel = form.find('label[for="contact-message"]');

    nameLabel.html('Full name');
    emailLabel.html('Email');
    numberLabel.html('Contact number');
    messageLabel.html('Message');

    var postdata = form.serialize();

    $.ajax({
        type: 'POST',
        url: 'sendmail.php',
        data: postdata,
        dataType: 'json',
        success: function(json) {
            if(json.nameMessage !== '') {
                nameLabel.append(' - &lt;span class="red error-label"&gt; ' + json.nameMessage + '&lt;/span&gt;');
            }
            if(json.emailMessage !== '') {
                emailLabel.append(' - &lt;span class="red error-label"&gt; ' + json.emailMessage + '&lt;/span&gt;');
            }
            if(json.numberMessage !== '') {
                numberLabel.append(' - &lt;span class="red error-label"&gt; ' + json.numberMessage + '&lt;/span&gt;');
            }
            if(json.messageMessage !== '') {
                messageLabel.append(' - &lt;span class="red error-label"&gt; ' + json.messageMessage + '&lt;/span&gt;');
            }
            if(json.nameMessage === '' &amp;&amp; json.emailMessage === '' &amp;&amp; json.numberMessage === '' &amp;&amp; json.messageMessage === '') {
                form.fadeOut('fast', function() {
                    form.parent('.contact-form').append('&lt;h2 class="text-center"&gt;&lt;span class="orange"&gt;Thanks for contacting us!&lt;/span&gt; We will get back to you very soon.&lt;/h2&gt;');
                });
            } 
        }
    });
});
</code></pre>