Home Answers Viewqa JavaScriptQuestions JavaScript regex validate validate Zip.

 
 


Java Coder
JavaScript regex validate validate Zip.
2 Answer(s)      a year ago
Posted in : JavaScript Questions

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 Pages:
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 Special character
javascript regex validate Special character   javascript regex validate Special character   <html> <head> <title>Zip...; 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
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 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
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
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">
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
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
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">
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 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
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
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
how to validate values in the dynamically created textboxes?
how to validate values in the dynamically created textboxes?  how to validate values in the dynamically created textboxes in HTML using javascript...;script language="javascript"> var n=1; //FUNCTION TO REMOVE TEXT BOX ELEMENT
jQuery to validate Email Address
jQuery to validate Email Address     ... that validate the email address  from server and displays on the user browser...: The following code includes the jQuery JavaScript library file: <script type
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
Zip Code Validation - Java Interview Questions
Zip Code Validation  Hi, Anyone can please send me a javascript function of the following --> Indian postal Zip Code Validation (Only 6 digits... should not be greater than to date  Hi friend, Code for Validate Zip
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. Thanks
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
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... 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
how to validate e,ail id and phne number in student form
="javascript:return validate();"> <table> <tr><td>Email <...how to validate e,ail id and phne number in student form  how to validate e,ail id and phne number in student form   Hi Friend, Try
Validate ID Number
Validate ID Number   How to validate South African ID Number using java.. I can do it using c# but, when it comes to java i;m clueless please help me   Here is a code that check whether the south African Id is valid
Validate 2 list boxes, one is multiselect, one is singleselect
Validate 2 list boxes, one is multiselect, one is singleselect  <head> <script language="javascript"> function... not support JavaScript!</noscript> </head> One list box contains
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist
how to validate javascriptcode n i am attaching file give validations
how to validate javascriptcode n i am attaching file give validations  <%@page import="java.sql.SQLException"%> <%@page import...,true); xmlhttp.send(); } <SCRIPT type="text/javascript">
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
form validate and perfom action immediatly
form validate and perfom action immediatly  This is ok, but what i'm looking for is whenever a user input different data his input has to validate and immediately he needs to redirect to a particular webpage based on the input

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.