Fax Number validation using RegularExpression (Regex) and JavaScript

Last Reply on Aug 06, 2015 08:46 AM By dharmendr

Posted on Aug 06, 2015 07:52 AM

any one send regular expression for fax validation.

 

Posted on Aug 06, 2015 08:46 AM Modified on on Aug 06, 2015 09:25 AM

Hi Bhargav,

This is the regular expression for fax format like

+(country code)-(area code)-(fax number)

var regex = new RegExp("\\+[0-9]{1,3}-[0-9]{3}\\-[0-9]{7}");

Or

var regex = new RegExp("^\\+[0-9]{1,3}-[0-9]{3}-[0-9]{7}$");

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ValidateFax() {
            var regex = new RegExp("^\\+[0-9]{1,3}-[0-9]{3}-[0-9]{7}$");
            var fax = document.getElementById("txtFax").value;
            if (fax != '') {
                if (regex.test(fax)) {
                    alert("Fax no is valid");
                } else {
                    alert("Fax no is invalid");
                }
            } else {
                alert("Enter Fax no.");
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="txtFax" type="text" />
        <input type="button" onclick="ValidateFax()" value="Validate" />
    </div>
    </form>
</body>
</html>

Demo

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html