Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions JavaScript regex validate Telephone no.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
JavaScript regex validate Telephone no.
2 Answer(s)      2 years and 5 months ago
Posted in : JavaScript Questions


JavaScript regex validate Telephone no.


Advertisement
View Answers

May 12, 2012 at 1:43 PM


 <html>
<head>
<title>Phone number validation using regex</title>
<script type="text/javascript">
    function validate() {
        var phone = document.getElementById("phone").value;
        var pattern = /^\d{3,5}([\-]\d{6,8})?$/;
        if (pattern.test(phone)) {
            alert("Your phone number : "+phone);
            return true;
        } 
            alert("It is not valid phone number!");
            return false;

    }
</script>

</head>
<body>
<h2>Validating phone number..</h2>
Enter Phone No. :
<input type="text" name="phone" id="phone" />
<input type="submit" value="Check" onclick="validate();" />
</body>
</html>


May 12, 2012 at 1:45 PM


The above example validate 10 digit (eg-9675647324) mobile number by using regular expression-

/^\d{3,5}([-]\d{6,8})$/; In this pattern u can put 3 to 5 length

of area code and ?? as a separator and 6 to 8 length of number. If you want to fix length 4 then put \d{4}.


Here /../(forward slashes) is used to quote your regular expression.

^ shows beginning of string.

\d{3,5} shows any digit 0-9 ranges 3 to 5.

[-] is used to put -.

$ is used for ending the string.

test() method takes one argument and check that to the pattern.



Related Tutorials/Questions & Answers:
JavaScript regex validate Telephone no.
JavaScript regex validate Telephone no.  JavaScript regex validate Telephone no.    <html> <head> <title>Phone number validation using regex</title> <script type="text/javascript">
JavaScript regex validate validate Zip.
JavaScript regex validate validate Zip.  JavaScript regex validate - how to validate Zip?   <html> <head> <title>Zip Code validation using regex</title> <script type="text/javascript">
Advertisements
javascript regex validate url
javascript regex validate url  How to validate URL in regex Javascript   <html> <head> <title>Url validation using regex</title> <script type="text/javascript"> function validate
JavaScript regex validate Mobile no.
JavaScript regex validate Mobile no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var mobile = document.getElementById("mobile").value
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
javascript regex validate currency
javascript regex validate currency  How to validate currency in JavaScript?   <html> <head> <title>Currency validation using regex</title> <script type="text/javascript"> function
javascript regex validate Special character
javascript regex validate Special character   javascript regex validate Special character   <html> <head> <title>Zip Code validation using regex</title> <script type="text/javascript">
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
javascript regex validation email
javascript regex validation email  How to write JavaScript regex... validation using regex</title> <script type="text/javascript"> function validate() { var email = document.getElementById("email").value
javascript regex validation alphanumeric
javascript regex validation alphanumeric  How to write javascript regex validation for alphanumeric?   <html> <head> <.../javascript"> function validate() { var name = document.getElementById
JavaScript regex exec() method for text match.
JavaScript regex exec() method for text match.  JavaScript regex exec...; regex exec() for text matching</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
RegEx
RegEx  I want to know the javascript RegEx code for validation of ( ) parenthesis.. The code is validating the parenthesis but after submit the parenthesis is disappear. what should i do
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript   <SCRIPT> function validateDate(dtControl) { var input = document.getElementById(dtControl) var validformat=/^\d{1,2}\/\d
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
validate select tag items in javascript
validate select tag items in javascript  Hi, How to validate addition of two numbers from two different <select> tag items in JavaScript..? Thanks in advance
telephone directory
telephone directory  how to make a telephone directory using arrays?   Hi Friend, Please visit the following link: Java Telephone Directory Thanks
Calling In JavaScript Functions from HTML Form To Validate User Entered Data
Calling In JavaScript Functions from HTML Form To Validate User Entered... and editing my html to call my functions to validate the user entered data...;title>Subscription Form</title> <script type="text/javascript">
Validate
Validate   hi all..im a beginner java and i need some help from u guys.. Its about validate. My HR request BF = 'brought forward', leave cannot apply date greater than 31/03 of particular year. So, if the user apply the date
Java REGEX
Java REGEX  I have a String {"name":"ashish","surname":"singh"} I have to check whether each word is surrounded by the " (double quotes) or not using the java regex. without using Json lib. Kindly help
JavaScript validate select tag
JavaScript validate select tag In this tutorial, you will learn how to validate html select tag. Here, we have used two select tags to select numbers...; <script language = "Javascript"> function validate
How do i validate form using javascript and send data to database?
How do i validate form using javascript and send data to database?  I need a "JOIN US" form that can validate using javascript and be able to connect....") return false; } } return true } function validate(){ var
replacing regex in large files
replacing regex in large files  replacing regex in large files
How to Validate dynamically created text box in HTML using Javascript
How to Validate dynamically created text box in HTML using Javascript  Here is the HTML code to create text boxes dynamically. It works properly.... And also how to validate the text boxes created dynamically. <html>
Recursive regex PHP - PHP
Recursive regex PHP  any one? that can send me the code of regular expression that checks other regular expression for its correctness.   Hi, Please check at http://www.roseindia.net/tutorial/php/phpbasics/PHP
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
long validate
long validate  How to validate long type
VoIP Telephone Adapter
VoIP Telephone Adapter          VoIP Telephone Adapter Services AT&T...) telephone service that utilizes the latest in Internet technology to deliver features
how to call from pc to telephone in java - MobileApplications
how to call from pc to telephone in java  Hi, presently I am working on "make a call from pc to telephone" in java. I am unable to procceed how to start. I am new this technoloy.Please give me some valuable suggestions how
Advertisements
 

 

 

DMCA.com