What's new

Closed Help validate telephone and phone

Status
Not open for further replies.

PHC-B L 4 C K

Honorary Poster
Joined
Mar 23, 2015
Posts
382
Reaction
152
Points
218
Hello po pa help po ng validation for telephone and phone number using javascript

<input type="number" id="validate" placeholder="Telephone or Phone">

example :

kapag po input ako ng "1234567890" mag aalert ng alert("invalid Telephone or Phone Number");

example :
kapag po input ko ng "1234567" or "09123456789" mag ssubmit na siya..
 
madali lang yan, basic regex lang yan. Kayang kaya mo yan. Do your reasearch well napakarami sa google ts.

di boss. regex for number only diba po? ang gusto ko po sana is pwede niya lang i input na number equal 7 or equal 11 numbers lang. kapag sobra incorrect na po
 
di boss. regex for number only diba po? ang gusto ko po sana is pwede niya lang i input na number equal 7 or equal 11 numbers lang. kapag sobra incorrect na po

Hindi mo pa yata na explore ang js regex. Hindi totoo yan. Hindi mo lang alam gamitin ng tama yung mga special characters.
 
or you can use php
tas bilangin mo ang input if 7 or 11 :) else, if other than 7 at 11, invalid na kasi dapat either telephone number at phone number lang sa pilipinas diba?

if you want, check mo rin if 11 siya, check mo if ang simula ay 09 else, mali/hindi phone number

teka try ko wahahhahah
 
Ito na okay na siya. Lagay mo lang sa isang .php file yang code na yan then run mo na :)
Code:
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    $txtNumber = $_POST['txtNumber'];
    if ($txtNumber == null) {
        echo "<script>alert('Can\'t be empty!');</script>";
    }else{
        if ((strlen($txtNumber) == "11") && (substr($txtNumber, 0,2) == "09")) {
            echo "<script>alert('Cellphone number');</script>";
        }else if (strlen($txtNumber) == "7") {
            echo "<script>alert('Telephone number');</script>";
        }else{
            echo "<script>alert('Invalid number!');</script>";
        }
    }
}
?>
<form action="#" method="post">
<center>
<input type="number" name="txtNumber" placeholder="Phone/Telephone" style="padding: 20px;">
<input type="submit" style="padding: 20px">
</center></form>
 
Ito na okay na siya. Lagay mo lang sa isang .php file yang code na yan then run mo na :)
Code:
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    $txtNumber = $_POST['txtNumber'];
    if ($txtNumber == null) {
        echo "<script>alert('Can\'t be empty!');</script>";
    }else{
        if ((strlen($txtNumber) == "11") && (substr($txtNumber, 0,2) == "09")) {
            echo "<script>alert('Cellphone number');</script>";
        }else if (strlen($txtNumber) == "7") {
            echo "<script>alert('Telephone number');</script>";
        }else{
            echo "<script>alert('Invalid number!');</script>";
        }
    }
}
?>
<form action="#" method="post">
<center>
<input type="number" name="txtNumber" placeholder="Phone/Telephone" style="padding: 20px;">
<input type="submit" style="padding: 20px">
</center></form>

Boss thanks. dito :) nag regex na lang po ako :) thank you very much for efforts
 
Status
Not open for further replies.
Back
Top