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



Home Answers Viewqa JavaScriptQuestions JavaScript regex validate validate Zip.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


JavaScript regex validate - how to validate Zip?


Advertisement
View Answers

May 12, 2012 at 1:34 PM


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

    }
</script>

</head>
<body>
<h2>Validating Zip Code..</h2>
Enter Zip Code :
<input type="text" name="zip" id="zip" />
<input type="submit" value="Check" onclick="validate();" />
</body>
</html>


May 12, 2012 at 1:36 PM


The above example validate 5 digit (eg-12344) or 5 digit-4 digit (eg- 12345-2323) zip code



by using regular expression- /^\d{5}([-]\d{4})?$/

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

^ shows beginning of string.

\d{5} is for any digit 0-9 having 5 places.

() is used for grouping content.

[-] is used to put -.



\d{4} having sequence of digits of 4 places.

$ is used for ending the string.

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



Related Tutorials/Questions & Answers:
JavaScript regex validate validate Zip.
JavaScript regex validate validate Zip.  JavaScript regex validate - how to validate Zip?   <html> <head> <title>Zip Code...; function validate() { var zip = document.getElementById("zip").value
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
Advertisements
JavaScript regex validate Telephone no.
JavaScript regex validate Telephone no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var phone = document.getElementById("phone").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 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 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...; function validate() { var zip = document.getElementById("zip").value
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
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
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
long validate
long validate  How to validate long type
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
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 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
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
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">
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
validate select option jquery
validate select option jquery  How to Validate select option in JQuery
validate() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
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>
validate bank account number
validate bank account number  how to validate bank account number in jsp
validate bank account number
validate bank account number  how to validate bank account number in jsp
validate parameter before using it
validate parameter before using it   How to validate the parameter before using it in JSP
Validate telnet connectivity
Validate telnet connectivity  How to validate telnet connectivity in my java code
validate() method of ActionForm work
validate() method of ActionForm work  How does validate() method of ActionForm work
reset() and Validate() method
reset() and Validate() method   How does reset() and Validate() method struts work
Advertisements
 

 

 

DMCA.com