Solved

Check if 4 digits is entered...

Posted on 2011-02-21
3
297 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 89
HTML page and JavaScript 2 55
HTML Lists 3 29
Making my existing website "mobile friendly"... 10 18
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now