Solved

Check if 4 digits is entered...

Posted on 2011-02-21
3
301 Views
Last Modified: 2012-05-11
Hi!

Have a script that the user must enter a value.
But he/she can enter text or numbers...

I like this script to validate the input from the user to:

MUST enter 4 numbers -> example: 3100 , 3288 , 6655 ...

If user dosent enter 4 numbers, the script must tell user to enter
a 4 digit number...

How do i modify my script to do this ?


<script type="text/javascript">
//<![CDATA[
    var showPrompt = function(href){
     husk_postnr2=prompt("Legg inn postnummer");
            if (husk_postnr2!=""&&husk_postnr2!=null){
                 window.location=href+"&postnr="+husk_postnr2;
	    }
        return false;
    }
//]]>
</script>

Open in new window

0
Comment
Question by:team2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 34941524
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 34941530
try

function checkpostcode(form)
{
var min = 4;
var numberFormat = /^\d{4}$/;

if (form.postcode.value.length == min)
{
if (numberFormat.test(form.postcode.value)
{
return true;
}
else
{
alert("Please enter a 4-digit postcode");
return false;
}
}
else
{
alert("Please enter a 4-digit postcode");
return false;
}
}


refer
http://bytes.com/topic/javascript/answers/90985-validate-form-4-digit-integer
0
 
LVL 2

Author Closing Comment

by:team2005
ID: 35122761
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Text too large in Chrome 17 83
Add a little space on either side of a table. 12 32
CSS Scroll Center with Static Side. Like EE does. 2 47
Hta File displays dynamic File names 4 65
This article discusses how to create an extensible mechanism for linked drop downs.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question