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



Home Answers Viewqa JavaScriptQuestions JavaScript regex validate validate Zip.

Have Programming Question? Ask it here!
 
 
 


Java Coder
JavaScript regex validate validate Zip.
2 Answer(s)      2 years and 2 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 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
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
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">
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
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 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 bank account number
validate bank account number  how to validate bank account number in jsp
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
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 text field iPhone
validate text field iPhone  i got two different UITextfield in my iPhone application for user login. Just wondering how to validate
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
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
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
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
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
How to validate a form - JSP-Servlet
How to validate a form   Dear Sir, I have a one jsp... want to validate a form1 i.e in form1 i have a text field for a Id values .If i....  Hi Friend, Try the following code: function validate(){ var
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">
how to validate national ID number
how to validate national ID number  hey guys, plz send me a code how to vlaidate national ID number using jtextfield. in ID num thers 9 numbers +V.the V letter is included at the end of the numbers. ex:123456789V i don knw how
Struts - Overrite of Validate method - Struts
Struts - Overrite of Validate method  i am trying to display error message on target page,by using this code ..when iam compliling i got errors.so... : public ActionErrors validate(ActionMapping mapping,HttpServletRequest req
Validate email id in jsp - JSP-Interview Questions
Validate email id in jsp  Hi Please Suggest me how to validate email id in JSP(Java Server Faces
Validate TextArea
Validate TextArea       In this section, you will learn how to validate your text area...; <s:form action="characterLimit1" method="POST" validate="true
Validate Domain of an Email Id - JSP-Servlet
Validate Domain of an Email Id  How to validate the domain name in an Email id before sending a mail for an application using Mail API. ex: a@a.com in the above email id i want to validate whether a.com is present
how to validate all form field values at once.
how to validate all form field values at once.  how to validate all form field values at once. condition:no form field shold contain sometext("--select
Advertisements
 

 

 

DMCA.com