Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex case sensitivity

Status
Not open for further replies.

TurboSRT4

Programmer
Nov 23, 2009
47
US
Sorry to keep bothering u guys but im new to using expressions i always did stuff the long and wrong way lol

I have this snippet
if ($first =~ /[\d\\\/~`@#\$\%^&*()-_\+\=\[\{\]\}\|\"\']/){
push @errors, qq(First Name Is Invalid<BR>);


}
it works ok if the string contains numbers or characters it pushes the error. The problem is if the string contains any capitals it also pushes the errors. Please, how do i make the comparison case insensitive. thank you
 
Hi

Oops, I missed that glitch. You have to escape the dash ( - ) in character classes unless it is at an end of the list.
Code:
[b]if[/b] [teal]([/teal][navy]$first[/navy] [teal]=~[/teal] [green][i]/[\d\\\/~`@#\$\%^&*()[highlight]\[/highlight]-_\+\=\[\{\]\}\|\"\']/[/i][/green][teal])[/teal][teal]{[/teal]
  [b]push[/b] [navy]@errors[/navy][teal],[/teal] [b]qq[/b][green][i](First Name Is Invalid<BR>)[/i][/green][teal];[/teal]
[teal]}[/teal]
( Let us keep the discussion in the original thread219-1605552 . This is not really a separate problem. )

Feherke.
 
Noticed the <BR> reference ... aka html code generation.

If your into helping your users out:
* Work the $& variable into the push command and you'll point out just what the code didn't like about the name versus keeping them guessing.
* To improve the above suggestion, add a + sign after the final ]
* Lastly, reconsider the \- exclusion. There may be someone who goes by Billy-Jo as their first name.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top