JavaScript regex validate validate Zip.

JavaScript regex validate validate Zip.

JavaScript regex validate - how to validate Zip?

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 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...; function validate() { var zip = document.getElementById("zip").value
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
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 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
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
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
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 <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
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
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() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
validate select option jquery
validate select option jquery  How to Validate select option in JQuery
reset() and Validate() method
reset() and Validate() method   How does reset() and Validate() method struts work
validate() method of ActionForm work
validate() method of ActionForm work  How does validate() method of ActionForm work
Validate telnet connectivity
Validate telnet connectivity  How to validate telnet connectivity in my java code
validate parameter before using it
validate parameter before using it   How to validate the parameter before using it in JSP
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
ModuleNotFoundError: No module named 'validate'
ModuleNotFoundError: No module named 'validate'  Hi, My Python... 'validate' How to remove the ModuleNotFoundError: No module named 'validate... to install padas library. You can install validate python with following
ModuleNotFoundError: No module named 'validate-it'
ModuleNotFoundError: No module named 'validate-it'  Hi, My Python... 'validate-it' How to remove the ModuleNotFoundError: No module named 'validate-it' error? Thanks   Hi, In your python environment
validate text field iPhone
validate text field iPhone  i got two different UITextfield in my iPhone application for user login. Just wondering how to validate
use of ActionMapping in validate()
use of ActionMapping in validate()  why do we pass actionmapping in validate(ActionMapping mapping,HttpServletRequest) even we don't use actionmapping in that method
validate input php
validate input php  How to validate the input fields in PHP & HTML.   Hi, Please let's know many fields is to be validated. Then I will make an example for you.ADS_TO_REPLACE_1 Thanks
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
validation using validate method
validation using validate method  HOW TO DO THE VALIDATION IN THE STRUTS 2 USING VALIDATE METHOD IN ACTION CLASS,AND ALSO AM HAVING MY BEAN CLASS AS SEPERATE. I HAD TRIED THAT BUT IT WAS NOT WORKING PROPERLY. IF U KNOW
how to validate the email login
how to validate the email login  // JavaScript Document JOIN US < aphone.length; i++) { temp = "" + aphone.substring(i, i...; } } return true } function validate(){ var fname=document.form.fname.value
preg_match validate
preg_match validate  what is preg_match and how can i use it to validate the input field.   Hi, in preg_match you can define any pattern... on the count value you can validate the input ?> Thanks
validate email objective c
validate email objective c  how can i validate email text field in objective c? is there any method that support multiple email address separated by coma.   - (BOOL)validateEmailWithString:(NSString*)email
Version of com.feiynn>feiynn-validate dependency
List of Version of com.feiynn>feiynn-validate dependency
ModuleNotFoundError: No module named 'kubernetes-validate'
ModuleNotFoundError: No module named 'kubernetes-validate'  Hi, My... named 'kubernetes-validate' How to remove the ModuleNotFoundError: No module named 'kubernetes-validate' error? Thanks   Hi
ModuleNotFoundError: No module named 'pycard-validate'
ModuleNotFoundError: No module named 'pycard-validate'  Hi, My... named 'pycard-validate' How to remove the ModuleNotFoundError: No module named 'pycard-validate' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-validate'
ModuleNotFoundError: No module named 'python-validate'  Hi, My... named 'python-validate' How to remove the ModuleNotFoundError: No module named 'python-validate' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'py-validate'
ModuleNotFoundError: No module named 'py-validate'  Hi, My Python... 'py-validate' How to remove the ModuleNotFoundError: No module named 'py-validate' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'scikit-validate'
ModuleNotFoundError: No module named 'scikit-validate'  Hi, My... named 'scikit-validate' How to remove the ModuleNotFoundError: No module named 'scikit-validate' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ss-validate'
ModuleNotFoundError: No module named 'ss-validate'  Hi, My Python... 'ss-validate' How to remove the ModuleNotFoundError: No module named 'ss-validate' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'validate-yaml'
ModuleNotFoundError: No module named 'validate-yaml'  Hi, My... 'validate-yaml' How to remove the ModuleNotFoundError: No module named 'validate-yaml' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'validate-yml'
ModuleNotFoundError: No module named 'validate-yml'  Hi, My Python... 'validate-yml' How to remove the ModuleNotFoundError: No module named 'validate-yml' error? Thanks   Hi, In your python

Ads