Closed Thread Icon

Topic awaiting preservation: bad stuff Pages that link to <a href="https://ozoneasylum.com/backlink?for=11952" title="Pages that link to Topic awaiting preservation: bad stuff" rel="nofollow" >Topic awaiting preservation: bad stuff\

 
Author Thread
maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 12-12-2001 05:11

ok, I know how to do this in perl, but I need to do it in php. I need to check that a string is only numbers, letters, spaces, and underscores. It doesn't have to be all of those, it just can't be something other than those. Any help would be greatly appreciated.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-12-2001 07:14

<?php

$input = "aAzZhH12390 _";

if (preg_match("/^[\w\x20]+$/", $input)) {
// $input string is ok
} else {
// $input string isn't ok
}

?>


maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 12-14-2001 01:07

are the characters used in regular expressions the same in php and perl?

http://www.maninacan.com

maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 12-14-2001 01:10

also, what does the \x20 part mean?

http://www.maninacan.com

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 12-14-2001 01:38

They are in a preg_reg match which use perl regular expression syntax.

As for the \x I'm not completely positive, but I think it removes any white space and comments.

If that's incorrect, I hope (know) someone will come along and correct me.

-Butcher-

maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 12-14-2001 02:15

yes, I did some looking and I think that's what the \x thing does, but then what's the 20 for, Maybe it's part of removing whitespace, because %20 is a space, hmmmm. Hopefully Mr. Max comes back here to tell me

http://www.maninacan.com

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 12-14-2001 02:19

You can count on mr.maX comming along here sooner or later.

Sorry I can't help you on the 20 part as I have just really started learning Perl and Regex myself recently.

maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 12-14-2001 02:22

can someone give me a quick email address validification php script as well, it'd be greatly appreciated.

http://www.maninacan.com

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 12-14-2001 02:55

If you mean just to check to see if it fits the proper form of an email address you can use this:

eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)



[This message has been edited by butcher (edited 12-14-2001).]

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-14-2001 07:09

\x doesn't remove anything, \x20 simply specifies character with hexadecimal value (20 hex = 32 dec = space).

<?php

// Written by mr.maX, http://www.maxworld.co.yu/

$email = "someone@example.com";

if (preg_match("/^[^\s]+?\@[^\s]+?\.\w{2,}$/", $email)) {
// $email string is ok
} else {
// $email string isn't ok
}

?>


mwasisco
Obsessive-Compulsive (I) Inmate

From: chicago, IL usa
Insane since: Jan 2003

posted posted 01-14-2003 22:23

Hello. I am trying to do the same, but the string must be four charachters. one letter followed by three numbers. the following works, but it allows more than three numbers. any suggestions?

function check_field1($password){
if (preg_match("/^[a-zA-Z]+[0-9]+[0-9]+[0-9]+$/s",$password)) return TRUE;
else return FALSE;
}

genis
Paranoid (IV) Inmate

From: Dallas, TX
Insane since: Aug 2002

posted posted 01-14-2003 22:31

preg should be:

/^([a-zA-Z]{1})([0-9]{3})$/s

mwasisco
Obsessive-Compulsive (I) Inmate

From: chicago, IL usa
Insane since: Jan 2003

posted posted 01-14-2003 22:47

thank you genis!

genis
Paranoid (IV) Inmate

From: Dallas, TX
Insane since: Aug 2002

posted posted 01-14-2003 23:05

no prob - and by the way, welcome!

maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 01-14-2003 23:12

wow, this topic got dug up again after over a year.

genis
Paranoid (IV) Inmate

From: Dallas, TX
Insane since: Aug 2002

posted posted 01-14-2003 23:26

wow, 13 months exactly... i didn't even notice.

anyway, here's a link i should've given that guy...

PCRE regex syntax for PHP

« BackwardsOnwards »

Show Forum Drop Down Menu