This content is not currently approved and is visible here for review only.

Library tutorials & articles

Validate Phone / Fax Number In Javascript

Introduction

There is one javascript function called "ValidateNo".

In this funciton there are two arguments

  1. NumStr : This is the value which you want to validate. It will come from your form       control. It may by TextBox control (HTML or ServerControl).
  2. String : This is predefined format which you can use to validate phone/fax number. It may contain +, - and space. You can modify it as per your requirement.

function ValidateNo(NumStr, String)
{
    for(var Idx=0; Idx<NumStr.length; Idx++)
    {
        var Char = NumStr.charAt(Idx);
        var Match = false;

        for(var Idx1=0; Idx1<String.length; Idx1++)
        {
            if(Char == String.charAt (Idx1))
                Match = true;
        }

        if (!Match)
            return false;
    }
    return true;
}


Now create on javascript function called "ValidateDetail".

function ValidateDetail()
{
    if(document.myform.phone.value == "")
    {
       alert("Please specify phone number");
       document.myform.phone.focus();
       return false;
    }

    if(!ValidateNo(document.myform.phone.value,"1234567890+- "))
    {
        alert("Please Enter Only Number");
        document.myform.phone.focus();
        return false;
    }

    return true;
}

Now you can call this javascript "ValidateDetail" function for validating your phone and fax number.


Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Validate Phone / Fax Number In Javascript.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • Java Posse #220 - JavaFX Launch and Interview

    JavaFX Launch and Interview Fully formatted shownotes can always be found at http://javaposse.com An Interview with John Burkey and Octavian Tanase of Sun Microsystems about JavaFX. The audio quality is telephone grade, you have been warned. JavaFX http://www.sun.com/software/javafx/ Octav...

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!