Solved

Check if 4 digits is entered...

Posted on 2011-02-21
3
300 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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

828 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