You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Johnson <ch...@gmail.com> on 2005/05/20 23:29:51 UTC
[OT] Help with REgular Expressions in Validate()
Hi all
I markled this OT because it's not a Struts question strictly speaking.
what I'm trying to do is disallow names that contain spaces or special
characters in the validate() method of my ActionForm
Code:
String pattern = "\\W+";
log.debug("Testing validity of name "+name+ " against "+pattern);
if (name!=null){
if (name.matches(pattern)) {
log.info("Naming Convention Violated");
e = new ActionError("error.create.portfolio.name.error");
errors.add("",new ActionError("error.create.portfolio.name.error"));
}else{
log.debug("Valid name chosen");
}
}
What am I missing?!?!?! I always get "valid name chosen"
Again, I want to allow "MyNAme" and disallow "My Name" or "MyName!" (due to
spaces or special characters
--
-Dave
ChaChaNY@Gmail.com
Re: [OT] Help with REgular Expressions in Validate()
Posted by Laurie Harper <la...@holoweb.net>.
Woops, that's me not reading the original post carefully!
meyawn wrote:
> wait a min...
> \w = word character: [a-zA-Z_0-9]
> \W (capital w) = non-word character: [^\w]
>
> so in case you wanna ban _ and digits you have to use
> "^[a-zA-Z]$"
>
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org]On Behalf Of Laurie Harper
> Sent: Saturday, May 21, 2005 11:47 PM
> To: user@struts.apache.org
> Subject: Re: [OT] Help with REgular Expressions in Validate()
>
>
> Or better yet, "^\\W+$", if whitespace is the only thing you want to
> exclude; your original expression says 'match one more non-whitespace
> characters', so with the input 'My Name' the expression matches 'My'.
> What you want to say is that the entire input must match \\W+, hence the
> ^/$.
>
> L.
>
> meyawn wrote:
>
>>try this as your pattern "^[a-z]+$"
>>this will match all lower case...you can use a modifier for ignoring
>
> case..i
>
>>think its "i" but am too lazy to look it up..figure it out yourself :)
>>
>>-----Original Message-----
>>From: Brady Hegberg [mailto:bradyh@bitstream.net]
>>Sent: Saturday, May 21, 2005 2:20 AM
>>To: Struts Users Mailing List
>>Subject: Re: [OT] Help with REgular Expressions in Validate()
>>
>>
>>I have a small swing application (setup on webstart) for testing regular
>>expressions here:
>>http://lili.net/java/test-regex.jnlp
>>
>>Or I can send you the code to test it yourself if you wish. it won't
>>fix your problem but it's a handy tool for narrowing it down.
>>
>>Brady
>>
>>
>>
>>>Hi all
>>>I markled this OT because it's not a Struts question strictly speaking.
>>>
>>>what I'm trying to do is disallow names that contain spaces or special
>>>characters in the validate() method of my ActionForm
>>>
>>>Code:
>>>String pattern = "\\W+";
>>>log.debug("Testing validity of name "+name+ " against "+pattern);
>>>if (name!=null){
>>>if (name.matches(pattern)) {
>>>log.info("Naming Convention Violated");
>>>e = new ActionError("error.create.portfolio.name.error");
>>>errors.add("",new ActionError("error.create.portfolio.name.error"));
>>>}else{
>>>log.debug("Valid name chosen");
>>>}
>>>}
>>>What am I missing?!?!?! I always get "valid name chosen"
>>>Again, I want to allow "MyNAme" and disallow "My Name" or "MyName!" (due
>>
>>to
>>
>>
>>>spaces or special characters
>>>
>>>
>>
>>--
>>Brady Hegberg <br...@bitstream.net>
>>
>>
>>---------------------------------------------------------------------
>>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: [OT] Help with REgular Expressions in Validate()
Posted by meyawn <na...@gmail.com>.
or if you want the negative of that
"^[^a-zA-Z]$"
-----Original Message-----
From: meyawn [mailto:nandan.info@gmail.com]
Sent: Saturday, May 21, 2005 11:53 PM
To: Struts Users Mailing List
Subject: RE: [OT] Help with REgular Expressions in Validate()
wait a min...
\w = word character: [a-zA-Z_0-9]
\W (capital w) = non-word character: [^\w]
so in case you wanna ban _ and digits you have to use
"^[a-zA-Z]$"
-----Original Message-----
From: news [mailto:news@sea.gmane.org]On Behalf Of Laurie Harper
Sent: Saturday, May 21, 2005 11:47 PM
To: user@struts.apache.org
Subject: Re: [OT] Help with REgular Expressions in Validate()
Or better yet, "^\\W+$", if whitespace is the only thing you want to
exclude; your original expression says 'match one more non-whitespace
characters', so with the input 'My Name' the expression matches 'My'.
What you want to say is that the entire input must match \\W+, hence the
^/$.
L.
meyawn wrote:
> try this as your pattern "^[a-z]+$"
> this will match all lower case...you can use a modifier for ignoring
case..i
> think its "i" but am too lazy to look it up..figure it out yourself :)
>
> -----Original Message-----
> From: Brady Hegberg [mailto:bradyh@bitstream.net]
> Sent: Saturday, May 21, 2005 2:20 AM
> To: Struts Users Mailing List
> Subject: Re: [OT] Help with REgular Expressions in Validate()
>
>
> I have a small swing application (setup on webstart) for testing regular
> expressions here:
> http://lili.net/java/test-regex.jnlp
>
> Or I can send you the code to test it yourself if you wish. it won't
> fix your problem but it's a handy tool for narrowing it down.
>
> Brady
>
>
>>Hi all
>>I markled this OT because it's not a Struts question strictly speaking.
>>
>>what I'm trying to do is disallow names that contain spaces or special
>>characters in the validate() method of my ActionForm
>>
>>Code:
>>String pattern = "\\W+";
>>log.debug("Testing validity of name "+name+ " against "+pattern);
>>if (name!=null){
>>if (name.matches(pattern)) {
>>log.info("Naming Convention Violated");
>>e = new ActionError("error.create.portfolio.name.error");
>>errors.add("",new ActionError("error.create.portfolio.name.error"));
>>}else{
>>log.debug("Valid name chosen");
>>}
>>}
>>What am I missing?!?!?! I always get "valid name chosen"
>> Again, I want to allow "MyNAme" and disallow "My Name" or "MyName!" (due
>
> to
>
>>spaces or special characters
>>
>>
>
> --
> Brady Hegberg <br...@bitstream.net>
>
>
> ---------------------------------------------------------------------
> 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: [OT] Help with REgular Expressions in Validate()
Posted by meyawn <na...@gmail.com>.
wait a min...
\w = word character: [a-zA-Z_0-9]
\W (capital w) = non-word character: [^\w]
so in case you wanna ban _ and digits you have to use
"^[a-zA-Z]$"
-----Original Message-----
From: news [mailto:news@sea.gmane.org]On Behalf Of Laurie Harper
Sent: Saturday, May 21, 2005 11:47 PM
To: user@struts.apache.org
Subject: Re: [OT] Help with REgular Expressions in Validate()
Or better yet, "^\\W+$", if whitespace is the only thing you want to
exclude; your original expression says 'match one more non-whitespace
characters', so with the input 'My Name' the expression matches 'My'.
What you want to say is that the entire input must match \\W+, hence the
^/$.
L.
meyawn wrote:
> try this as your pattern "^[a-z]+$"
> this will match all lower case...you can use a modifier for ignoring
case..i
> think its "i" but am too lazy to look it up..figure it out yourself :)
>
> -----Original Message-----
> From: Brady Hegberg [mailto:bradyh@bitstream.net]
> Sent: Saturday, May 21, 2005 2:20 AM
> To: Struts Users Mailing List
> Subject: Re: [OT] Help with REgular Expressions in Validate()
>
>
> I have a small swing application (setup on webstart) for testing regular
> expressions here:
> http://lili.net/java/test-regex.jnlp
>
> Or I can send you the code to test it yourself if you wish. it won't
> fix your problem but it's a handy tool for narrowing it down.
>
> Brady
>
>
>>Hi all
>>I markled this OT because it's not a Struts question strictly speaking.
>>
>>what I'm trying to do is disallow names that contain spaces or special
>>characters in the validate() method of my ActionForm
>>
>>Code:
>>String pattern = "\\W+";
>>log.debug("Testing validity of name "+name+ " against "+pattern);
>>if (name!=null){
>>if (name.matches(pattern)) {
>>log.info("Naming Convention Violated");
>>e = new ActionError("error.create.portfolio.name.error");
>>errors.add("",new ActionError("error.create.portfolio.name.error"));
>>}else{
>>log.debug("Valid name chosen");
>>}
>>}
>>What am I missing?!?!?! I always get "valid name chosen"
>> Again, I want to allow "MyNAme" and disallow "My Name" or "MyName!" (due
>
> to
>
>>spaces or special characters
>>
>>
>
> --
> Brady Hegberg <br...@bitstream.net>
>
>
> ---------------------------------------------------------------------
> 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: [OT] Help with REgular Expressions in Validate()
Posted by Laurie Harper <la...@holoweb.net>.
Or better yet, "^\\W+$", if whitespace is the only thing you want to
exclude; your original expression says 'match one more non-whitespace
characters', so with the input 'My Name' the expression matches 'My'.
What you want to say is that the entire input must match \\W+, hence the
^/$.
L.
meyawn wrote:
> try this as your pattern "^[a-z]+$"
> this will match all lower case...you can use a modifier for ignoring case..i
> think its "i" but am too lazy to look it up..figure it out yourself :)
>
> -----Original Message-----
> From: Brady Hegberg [mailto:bradyh@bitstream.net]
> Sent: Saturday, May 21, 2005 2:20 AM
> To: Struts Users Mailing List
> Subject: Re: [OT] Help with REgular Expressions in Validate()
>
>
> I have a small swing application (setup on webstart) for testing regular
> expressions here:
> http://lili.net/java/test-regex.jnlp
>
> Or I can send you the code to test it yourself if you wish. it won't
> fix your problem but it's a handy tool for narrowing it down.
>
> Brady
>
>
>>Hi all
>>I markled this OT because it's not a Struts question strictly speaking.
>>
>>what I'm trying to do is disallow names that contain spaces or special
>>characters in the validate() method of my ActionForm
>>
>>Code:
>>String pattern = "\\W+";
>>log.debug("Testing validity of name "+name+ " against "+pattern);
>>if (name!=null){
>>if (name.matches(pattern)) {
>>log.info("Naming Convention Violated");
>>e = new ActionError("error.create.portfolio.name.error");
>>errors.add("",new ActionError("error.create.portfolio.name.error"));
>>}else{
>>log.debug("Valid name chosen");
>>}
>>}
>>What am I missing?!?!?! I always get "valid name chosen"
>> Again, I want to allow "MyNAme" and disallow "My Name" or "MyName!" (due
>
> to
>
>>spaces or special characters
>>
>>
>
> --
> Brady Hegberg <br...@bitstream.net>
>
>
> ---------------------------------------------------------------------
> 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: [OT] Help with REgular Expressions in Validate()
Posted by meyawn <na...@gmail.com>.
try this as your pattern "^[a-z]+$"
this will match all lower case...you can use a modifier for ignoring case..i
think its "i" but am too lazy to look it up..figure it out yourself :)
-----Original Message-----
From: Brady Hegberg [mailto:bradyh@bitstream.net]
Sent: Saturday, May 21, 2005 2:20 AM
To: Struts Users Mailing List
Subject: Re: [OT] Help with REgular Expressions in Validate()
I have a small swing application (setup on webstart) for testing regular
expressions here:
http://lili.net/java/test-regex.jnlp
Or I can send you the code to test it yourself if you wish. it won't
fix your problem but it's a handy tool for narrowing it down.
Brady
> Hi all
> I markled this OT because it's not a Struts question strictly speaking.
>
> what I'm trying to do is disallow names that contain spaces or special
> characters in the validate() method of my ActionForm
>
> Code:
> String pattern = "\\W+";
> log.debug("Testing validity of name "+name+ " against "+pattern);
> if (name!=null){
> if (name.matches(pattern)) {
> log.info("Naming Convention Violated");
> e = new ActionError("error.create.portfolio.name.error");
> errors.add("",new ActionError("error.create.portfolio.name.error"));
> }else{
> log.debug("Valid name chosen");
> }
> }
> What am I missing?!?!?! I always get "valid name chosen"
> Again, I want to allow "MyNAme" and disallow "My Name" or "MyName!" (due
to
> spaces or special characters
>
>
--
Brady Hegberg <br...@bitstream.net>
---------------------------------------------------------------------
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: [OT] Help with REgular Expressions in Validate()
Posted by Brady Hegberg <br...@bitstream.net>.
I have a small swing application (setup on webstart) for testing regular
expressions here:
http://lili.net/java/test-regex.jnlp
Or I can send you the code to test it yourself if you wish. it won't
fix your problem but it's a handy tool for narrowing it down.
Brady
> Hi all
> I markled this OT because it's not a Struts question strictly speaking.
>
> what I'm trying to do is disallow names that contain spaces or special
> characters in the validate() method of my ActionForm
>
> Code:
> String pattern = "\\W+";
> log.debug("Testing validity of name "+name+ " against "+pattern);
> if (name!=null){
> if (name.matches(pattern)) {
> log.info("Naming Convention Violated");
> e = new ActionError("error.create.portfolio.name.error");
> errors.add("",new ActionError("error.create.portfolio.name.error"));
> }else{
> log.debug("Valid name chosen");
> }
> }
> What am I missing?!?!?! I always get "valid name chosen"
> Again, I want to allow "MyNAme" and disallow "My Name" or "MyName!" (due to
> spaces or special characters
>
>
--
Brady Hegberg <br...@bitstream.net>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org