aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes regular expression validation script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "regular expression validation script" Watch "regular expression validation script" New topic
Author

regular expression validation script

mohan kumar r
Ranch Hand

Joined: Jan 19, 2006
Posts: 38
hi,

i want to add validation for text field so that user can enter only comma seperated list of digits.

i have added the following validation
-------------------------------------------------------------------
if ( !(/^[0-9]*[0-9,]*[0-9]$/.test(document.myForm.myfield.value )))
---------------------------------------------------------------------
but it accepting input of the form 2,3,4,,5,,6 which is invalid.it should not accept comma followed by comma.
is it possible to do by using reguler expression.


mohan
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
* means it must occur or more times. Do you see the problem in your code?

You should be doing something more like

(\d+,)*\d+

Eric
mohan kumar r
Ranch Hand

Joined: Jan 19, 2006
Posts: 38
my requirement is that ' it should be comma separated list of digits'. and duplicate commas are not allowed.

i have also tried like this:
--------------------------
if(!(/^[0-9]*[0-9]*[,]?[0-9]*$/.test(document.myform.mytext.value)))
{
alert("not valid");
document.myform.mytext.focus();
}
-----------------------------
but this too is not working
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Did you try mine?

Eric
mohan kumar r
Ranch Hand

Joined: Jan 19, 2006
Posts: 38
thank you Eric, it is working fine
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regular expression validation script