File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "help" Watch "help" New topic
Author

help

jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
whats wrong with this function in javascripting..
trying to validate the year field so that the user can insert in only numeric fields and not more than 4 digits..
function checkNumber(year)
{
year += "";
StrRE2 = /[^0-9]/;
if(year.match(StrRE2)||year.length!=4)
{
alert="Please enter only numeric values and not more than 4 digits"
}
else
{
return true
}
}
jyothsna kumari
Ranch Hand

Joined: Jul 21, 2003
Posts: 108
hi,
If the problem you are facing is in displaying the alert msg then it should be like this.
if(year.match(StrRE2)||year.length!=4)
{
alert("Please enter only numeric values and not more than 4 digits")
}
Other than that i don't find any thing wrong.
Jyothsna
jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
ya ..right.. got to be little cool - headed..
got it workng..bt iam also trying to validate the year so that user should not mistakenly enter more or less than 4 digits..that is still stuck up

anyways..thanks..
himanshu patel
Ranch Hand

Joined: Feb 03, 2003
Posts: 205
Alternatively you can use isNaN function as shown below.
function checkNumber(year)
{
if(isNaN(year) || year.length != 4)
{
alert("Please enter only numeric values and not more than 4 digits");
}
else
{
alert("Valid year");
}
}


If you want to become a rich, do not work for others but make others to work for you.
 
 
subject: help
 
Threads others viewed
validation for a numeric field
validating a range of values
Validation Using Regular Expression in Javascript
Max Date Limit
JTextField's text property not being set?
developer file tools