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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if statement question 1

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
0
0
CA
I'm using this to print he guestbook entries to a web browser:

if ($vars[12] =~ /[a-zA-Z0-9]+/) {
blah...blah...blah
}

Well, the [a-zA-Z0-9]+ causes a problem on my guestbook if someone uses ONLY a censored word. It would appear with *'s and corrupt the entry table.

So, my question is what can I change the [a-zA-Z0-9]+ to so instead of looking for only letters and numbers, it searches for any character? Thanks! Web site: Email: calvin@puremadnezz.com
AIM: XCalvin1984
MSN: xcloud2000x@hotmail.com
ICQ: 135616065 (I don't really use ICQ alot.)
Yahoo Messenger: xcloud2000x (I don't really use Yahoo messenger alot.)

Contact me for any programming help and whatnot.
 
What do you mean by "any character"? Do you mean any PRINTABLE character, or any ASCII character (x00 - xFF), or what? Any character is
Code:
/.+/
. But in that case you could just check that the variable is not null instead of using a regex. For any printable character, you could use a range of hex values, for example
Code:
/[x20-xff]+/
would omit control characters. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
THANK YOU!!!

I changed all the if statements to if ($vars[12] =~ /.+/) { and it worked perfectly!

STAR TIME! ;-) Web site: Email: calvin@puremadnezz.com
AIM: XCalvin1984
MSN: xcloud2000x@hotmail.com
ICQ: 135616065 (I don't really use ICQ alot.)
Yahoo Messenger: xcloud2000x (I don't really use Yahoo messenger alot.)

Contact me for any programming help and whatnot.
 
One more question. I'm using this to check emails: /\w+@\w+\.\w+/

Would it work if I make it: /\.+@\.+\.\.+/ ?

The reason I want to do that is because every field in my guestbook is censored and if someone entered 'test@test.com' as an email it would appear as '****@***.com', thus displaying the invalid email address error.

Thanks. Web site: Email: calvin@puremadnezz.com
AIM: XCalvin1984
MSN: xcloud2000x@hotmail.com
ICQ: 135616065 (I don't really use ICQ alot.)
Yahoo Messenger: xcloud2000x (I don't really use Yahoo messenger alot.)

Contact me for any programming help and whatnot.
 
You can do so, though it will leave you open to bad emails addresses, e.g.
'abc def/\\+ @oh my god. forgive#me'
Jean Spector
QA Engineer @ mSAFE Ltd.
 
Then how do I edit that to just accept * characters? :) Web site: Email: calvin@puremadnezz.com
AIM: XCalvin1984
MSN: xcloud2000x@hotmail.com
ICQ: 135616065 (I don't really use ICQ alot.)
Yahoo Messenger: xcloud2000x (I don't really use Yahoo messenger alot.)

Contact me for any programming help and whatnot.
 
Do you mean that if someone types in

test@test.com

then your program sees

****@****.com

??? If so, I guess you could do

/^\*+@\*+\.\w+$

I'm just guessing. That really doesn't seem right to me that most of the email address is asterisk'd out. You really should try to describe your situation better.
Hardy Merrill
Mission Critical Linux, Inc.
 
You can add an asterisk to your character class just by sticking it in there (no need to escape it) like this:
Code:
/^[a-zA-Z0-9*]+@[a-zA-Z0-9*]+\.[a-zA-Z0-9*]+$/
To include other characters, just add them to the character class, it doesn't have to be ranges of characters. Remember that you don't have to escape special characters in the class. The only special things to remember is that if you want a hyphen to be part of the class it has to be the FIRST character after the [, and if you want a ^ to be part of the class, it CANNOT be the first (otherwise it negates the class). I'm not sure how to go about making [ or ] a part of a class, but I'd use the hex codes for them. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top