Fax Number validation using RegularExpression (Regex) and JavaScript

Last Reply one year ago By dharmendr

Posted one year ago

any one send regular expression for fax validation.

 

Posted one year ago Modified on one year ago

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: http://e-iceblue.com/free-api