You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sr...@wachovia.com on 2007/08/01 02:11:57 UTC

Help in using regex in Validation.xml

Hi,

This question can be termed as an OT as it is related to regex. I have a 
validation criteria which says:

a number cannot start with "000" which is 9 digits in length.

Can somebody help me in writing a regular expression for this?

Thank you

RE: Help in using regex in Validation.xml

Posted by sr...@wachovia.com.
Actually, I managed to get the correct expression for the condition

^(?!000)\d{9}$

Seems to work!!!



"Rod Bollinger" <te...@portablegenius.com> 
08/01/2007 11:05 AM

Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
"'Struts Users Mailing List'" <us...@struts.apache.org>
cc

Subject
RE: Help in using regex in Validation.xml






Ouch! You are correct. :-(

I was looking at this a little more and I thought it would be nice to be
able to do something like ^[001-999]\d{6}$ where the first three positions
must be in the range of 001 through 999 (effectively filtering out the 000
case). Unfortunately, the [] operator can not be used in this fashion.

I was not able to figure out how to properly represent this idea but I 
would
be interested if some RegEx guru out there has any ideas.

Thanks,
-Rod

-----Original Message-----
From: Christopher Loschen [mailto:CLoschen@axeda.com] 
Sent: Wednesday, August 01, 2007 13:47
To: Struts Users Mailing List
Subject: RE: Help in using regex in Validation.xml

Not quite.

With the regex ^000\d{6}$, if you DON'T get a match, the input could be
any length and might not even be a number: after all, it isn't matching.
All this checks is the particular case where you have a 9-digit number
which starts with 000: any of the other possible problems aren't
addressed.

Chris

-----Original Message-----
From: Rod Bollinger [mailto:techinfo@portablegenius.com] 
Sent: Wednesday, August 01, 2007 10:33 AM
To: 'Struts Users Mailing List'
Subject: RE: Help in using regex in Validation.xml

This won't actually work. The parentheses should be braces and if you
don't
supply the start ("^") and end ("$") delimiters you will match
nine-digit
patterns within larger patterns as well (which I assume you don't want).

The correct simple syntax is: ^000\d{6}$

In your code, if you DON'T get a match, you have a valid nine-digit
number
(i.e. a number that is nine digits in length and DOES NOT start with
"000").

If you DO match, you have an invalid item.

HTH,
-Rod

-----Original Message-----
From: Jasper Floor [mailto:jasperfloor@gmail.com] 
Sent: Wednesday, August 01, 2007 06:17
To: Struts Users Mailing List
Subject: Re: Help in using regex in Validation.xml

On 8/1/07, sriharsha.chevuru@wachovia.com
<sr...@wachovia.com> wrote:
> Hi,
>
> This question can be termed as an OT as it is related to regex. I have
a
> validation criteria which says:
>
> a number cannot start with "000" which is 9 digits in length.
>
> Can somebody help me in writing a regular expression for this?

What exactly are the criteria?
If its only a nine digit number that cannot start with 000 then I
would look for a number which does start with 000

000\d(6)

if it matches you know it's wrong.

If the number of digits are variable, or you want to catch 00, 100
011, then it gets a little more difficult.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


ForwardSourceID:NT000080BA 

RE: Help in using regex in Validation.xml

Posted by Rod Bollinger <te...@portablegenius.com>.
Ouch! You are correct. :-(

I was looking at this a little more and I thought it would be nice to be
able to do something like ^[001-999]\d{6}$ where the first three positions
must be in the range of 001 through 999 (effectively filtering out the 000
case). Unfortunately, the [] operator can not be used in this fashion.

I was not able to figure out how to properly represent this idea but I would
be interested if some RegEx guru out there has any ideas.

Thanks,
-Rod

-----Original Message-----
From: Christopher Loschen [mailto:CLoschen@axeda.com] 
Sent: Wednesday, August 01, 2007 13:47
To: Struts Users Mailing List
Subject: RE: Help in using regex in Validation.xml

Not quite.

With the regex ^000\d{6}$, if you DON'T get a match, the input could be
any length and might not even be a number: after all, it isn't matching.
All this checks is the particular case where you have a 9-digit number
which starts with 000: any of the other possible problems aren't
addressed.

Chris

-----Original Message-----
From: Rod Bollinger [mailto:techinfo@portablegenius.com] 
Sent: Wednesday, August 01, 2007 10:33 AM
To: 'Struts Users Mailing List'
Subject: RE: Help in using regex in Validation.xml

This won't actually work. The parentheses should be braces and if you
don't
supply the start ("^") and end ("$") delimiters you will match
nine-digit
patterns within larger patterns as well (which I assume you don't want).

The correct simple syntax is: ^000\d{6}$

In your code, if you DON'T get a match, you have a valid nine-digit
number
(i.e. a number that is nine digits in length and DOES NOT start with
"000").

If you DO match, you have an invalid item.

HTH,
-Rod

-----Original Message-----
From: Jasper Floor [mailto:jasperfloor@gmail.com] 
Sent: Wednesday, August 01, 2007 06:17
To: Struts Users Mailing List
Subject: Re: Help in using regex in Validation.xml

On 8/1/07, sriharsha.chevuru@wachovia.com
<sr...@wachovia.com> wrote:
> Hi,
>
> This question can be termed as an OT as it is related to regex. I have
a
> validation criteria which says:
>
> a number cannot start with "000" which is 9 digits in length.
>
> Can somebody help me in writing a regular expression for this?

What exactly are the criteria?
If its only a nine digit number that cannot start with 000 then I
would look for a number which does start with 000

000\d(6)

if it matches you know it's wrong.

If the number of digits are variable, or you want to catch 00, 100
011, then it gets a little more difficult.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Help in using regex in Validation.xml

Posted by sr...@wachovia.com.
I appologise for the incomplete information. 

Let us assume that I address the length to be 9 and type to be digits 
criteria then this expression seems to address the not condition. 

Now, how do i use this expression in validation.xml, without actually 
writing my custom validator?

Some pointers would be of great help. 



"Christopher Loschen" <CL...@axeda.com> 
08/01/2007 10:47 AM

Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
"Struts Users Mailing List" <us...@struts.apache.org>
cc

Subject
RE: Help in using regex in Validation.xml






Not quite.

With the regex ^000\d{6}$, if you DON'T get a match, the input could be
any length and might not even be a number: after all, it isn't matching.
All this checks is the particular case where you have a 9-digit number
which starts with 000: any of the other possible problems aren't
addressed.

Chris

-----Original Message-----
From: Rod Bollinger [mailto:techinfo@portablegenius.com] 
Sent: Wednesday, August 01, 2007 10:33 AM
To: 'Struts Users Mailing List'
Subject: RE: Help in using regex in Validation.xml

This won't actually work. The parentheses should be braces and if you
don't
supply the start ("^") and end ("$") delimiters you will match
nine-digit
patterns within larger patterns as well (which I assume you don't want).

The correct simple syntax is: ^000\d{6}$

In your code, if you DON'T get a match, you have a valid nine-digit
number
(i.e. a number that is nine digits in length and DOES NOT start with
"000").

If you DO match, you have an invalid item.

HTH,
-Rod

-----Original Message-----
From: Jasper Floor [mailto:jasperfloor@gmail.com] 
Sent: Wednesday, August 01, 2007 06:17
To: Struts Users Mailing List
Subject: Re: Help in using regex in Validation.xml

On 8/1/07, sriharsha.chevuru@wachovia.com
<sr...@wachovia.com> wrote:
> Hi,
>
> This question can be termed as an OT as it is related to regex. I have
a
> validation criteria which says:
>
> a number cannot start with "000" which is 9 digits in length.
>
> Can somebody help me in writing a regular expression for this?

What exactly are the criteria?
If its only a nine digit number that cannot start with 000 then I
would look for a number which does start with 000

000\d(6)

if it matches you know it's wrong.

If the number of digits are variable, or you want to catch 00, 100
011, then it gets a little more difficult.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


ForwardSourceID:NT000080A2 

RE: Help in using regex in Validation.xml

Posted by Christopher Loschen <CL...@axeda.com>.
Not quite.

With the regex ^000\d{6}$, if you DON'T get a match, the input could be
any length and might not even be a number: after all, it isn't matching.
All this checks is the particular case where you have a 9-digit number
which starts with 000: any of the other possible problems aren't
addressed.

Chris

-----Original Message-----
From: Rod Bollinger [mailto:techinfo@portablegenius.com] 
Sent: Wednesday, August 01, 2007 10:33 AM
To: 'Struts Users Mailing List'
Subject: RE: Help in using regex in Validation.xml

This won't actually work. The parentheses should be braces and if you
don't
supply the start ("^") and end ("$") delimiters you will match
nine-digit
patterns within larger patterns as well (which I assume you don't want).

The correct simple syntax is: ^000\d{6}$

In your code, if you DON'T get a match, you have a valid nine-digit
number
(i.e. a number that is nine digits in length and DOES NOT start with
"000").

If you DO match, you have an invalid item.

HTH,
-Rod

-----Original Message-----
From: Jasper Floor [mailto:jasperfloor@gmail.com] 
Sent: Wednesday, August 01, 2007 06:17
To: Struts Users Mailing List
Subject: Re: Help in using regex in Validation.xml

On 8/1/07, sriharsha.chevuru@wachovia.com
<sr...@wachovia.com> wrote:
> Hi,
>
> This question can be termed as an OT as it is related to regex. I have
a
> validation criteria which says:
>
> a number cannot start with "000" which is 9 digits in length.
>
> Can somebody help me in writing a regular expression for this?

What exactly are the criteria?
If its only a nine digit number that cannot start with 000 then I
would look for a number which does start with 000

000\d(6)

if it matches you know it's wrong.

If the number of digits are variable, or you want to catch 00, 100
011, then it gets a little more difficult.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Help in using regex in Validation.xml

Posted by Rod Bollinger <te...@portablegenius.com>.
This won't actually work. The parentheses should be braces and if you don't
supply the start ("^") and end ("$") delimiters you will match nine-digit
patterns within larger patterns as well (which I assume you don't want).

The correct simple syntax is: ^000\d{6}$

In your code, if you DON'T get a match, you have a valid nine-digit number
(i.e. a number that is nine digits in length and DOES NOT start with "000").

If you DO match, you have an invalid item.

HTH,
-Rod

-----Original Message-----
From: Jasper Floor [mailto:jasperfloor@gmail.com] 
Sent: Wednesday, August 01, 2007 06:17
To: Struts Users Mailing List
Subject: Re: Help in using regex in Validation.xml

On 8/1/07, sriharsha.chevuru@wachovia.com
<sr...@wachovia.com> wrote:
> Hi,
>
> This question can be termed as an OT as it is related to regex. I have a
> validation criteria which says:
>
> a number cannot start with "000" which is 9 digits in length.
>
> Can somebody help me in writing a regular expression for this?

What exactly are the criteria?
If its only a nine digit number that cannot start with 000 then I
would look for a number which does start with 000

000\d(6)

if it matches you know it's wrong.

If the number of digits are variable, or you want to catch 00, 100
011, then it gets a little more difficult.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Help in using regex in Validation.xml

Posted by Jasper Floor <ja...@gmail.com>.
On 8/1/07, sriharsha.chevuru@wachovia.com
<sr...@wachovia.com> wrote:
> Hi,
>
> This question can be termed as an OT as it is related to regex. I have a
> validation criteria which says:
>
> a number cannot start with "000" which is 9 digits in length.
>
> Can somebody help me in writing a regular expression for this?

What exactly are the criteria?
If its only a nine digit number that cannot start with 000 then I
would look for a number which does start with 000

000\d(6)

if it matches you know it's wrong.

If the number of digits are variable, or you want to catch 00, 100
011, then it gets a little more difficult.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org