Home Answers Viewqa JavaScriptQuestions javascript regex validate Special character

 
 


Java Coder
javascript regex validate Special character
2 Answer(s)      a year ago
Posted in : JavaScript Questions

javascript regex validate Special character

View Answers

May 11, 2012 at 10:59 AM


<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 11, 2012 at 10:59 AM


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 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">
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate...;   The above example validate character value by using regular.... \W shows the special character. test() method takes one argument and check
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate Character.   <html> <head> <title>Character validation...; The above example validate character value by using regular expression- /\w
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">
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 currency
javascript regex validate currency  How to validate currency in JavaScript?   <html> <head> <title>Currency validation using regex</title> <script type="text/javascript"> function
password validation with special character
password validation with special character  how to validate password with special character using java script
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 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">
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
Regex Language Intro
Java: Regex Language Intro Regular expressions are a programming language... to understand which characters are metacharacters (have a special meaning), and which... basic concepts are important: character classes, quantifiers, boundaries
How to avoid the Special characters? - JDBC
and if someone enters special character (like single quote ') in text field (ex L'orel) and submit, it gives a error. I know this is a special character conflict, but how... special character. Does anyone has any idea how it will be possible. Thanks
Regex Literal Characters
Java: Regex Literal Characters [SERIOUSLY UNDER CONSTRUCTION] Most... to write in a Java string and they have not special meaning to the regular expression engine. But some characters are not easily entered or have special
On Javascript
number validation, date validation, special character validation, etc
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
javascript for prompt - JSP-Servlet
a prompt contains any special character or what.If contains a alert message has to come toremove a special character.I done but when an alert message come press ok...javascript for prompt  Dear Sir, I am using a prompt() for taking
Regex Exercises 2
: ___________________________________ Regex that matches any character followed by 'x'. Regex... Java: Regex Exercises 2 This is another example of regular... regex; String result; . . . Pattern pat = Pattern.compile(regex); Matcher mat
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
replace special characters in html
replace special characters in html  How can i replace the special characters in HTML?   Special Character in HTML HTML has a long list... it as it is. So, there it required to change those special character symbol to correct
PHP - Match Special Characters - PHP
PHP - Match Special Characters  a PHP script that match for special character before submitting it to database
MySQL :Regex Example
MySQL :Regex Example In this tutorial we are going to discuss about regex with example in JDBC. MySQL : Regex You can use Regular Expressions in mysql..., it is used as hardcoded Regex under any condition. Meta characters used by Regular
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 Form validation Example
Javascript Form validation Example In this section we will discuss about how to validate your application form in javascript. In many applications data... inserted is correct or not you will be required to validate your form. Here I
Summary - Character
Java: Summary - Character Character class static methods In this section we will see the static methods of Character class. Character class of Java API... for manipulating the strings. Most important use of Character class is to convert the data
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
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
problems in parsing the xml with the special characters
problems in parsing the xml with the special characters  Hi, I have a problem, in while parsing the xml with special characters apstrophe('). I am... to unescape the character ('). below is the sample one: private String escape
Character Wrapper Class.
. There are special characters in UNICODE to achieve the RTL. Such character is the Mirroring...Character Wrapper Class.  what are Mirrored Unicode Characters?? and whats the use of "isMirrored(ch);method ??.where ch is any character argument
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
Escaping Special Characters in a Pattern
characters and replaces all the detected special characters by "F" character and display whole string with the "F" character place of any special... Escaping Special Characters in a Pattern   
find the first character is vowel or not
find the first character is vowel or not  hi friend, can u plz send me javascript code for find the wether the first character is a vowel or not. 2) check wether the last character is same as the first character or not 3) check
Javascript
" method="post" onsubmit="javascript:return validate();"> Phone Number:<... this format xxx-xxx-xxxx, i want the code in javascript. as a function.   Javascript Phone Number Validation <html> <script> function
JavaScript - JavaScript Tutorial
how to immediately put JavaScript to validate forms, calculate values, work... is JSP using JavaScript I this example we will show you how to validate... of Unicode character values.     JavaScript method
javascript
javascript  please tell me sir,this query not validating correctly..whats wrong in this query? <HTML> <HEAD> <TITLE>validate <Script language = JavaScript> function validate(theForm) { var why=""; why
Removing character from a string in sql.
Removing character from a string in sql.  Removing special characters from a string in sql
javascript
javascript  <HTML> <HEAD> <TITLE>validate <Script language = JavaScript> function validate(theForm) { var why=""; why... = JavaScript> function validate() { var checkD= checkDropdown
javascript
javascript  Hi deepak, sample example on javascript form validation... charachters accepted are A - Z and a - z");return 0;} } function validate... name="form" method="post" onsubmit="return validate();"> <table> <
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
Regex Examples
Java: Regex Examples RegexMatches Finding the domain name in HTML links. <a +href="http://([\w\.-]+)OK. The domain name in an HTML..., stopping when a character after the domain name is found. However
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
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>
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">
replacing regex in large files
replacing regex in large files  replacing regex in large files

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.