By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,808 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,808 IT Pros & Developers. It's quick & easy.

preg_match allowing a-z AND

P: n/a
I've been searching the net and Google news groups for a preg_match
expression that will return true on strings containing (uppercase and
lowercase) characters of A-Z, 0-9 and for instance Swedish characters .
It should return false on strings containing stuff like -#%\"[]()=?&/.

The thing is, I don't want to specifically allow , I want a more
general rule in case other characters like or turn up. Is this possible
to do?

I've tried
preg_match("/^\w+$/", $string)
and
preg_match("/^[[:alpha:]]+$/", $string)

but both returns false on everything except a-z A-Z.

I'm going to use it to test a receiver's name ($to_name) before putting it
in an e-mail header like "$to_name <$to_email>"; The names are entered in a
text field by my users and I want to test the name so it won't mess up the
e-mail header causing the e-mail to fail.

Any help would be greatly appreciated. Thank you.

Daniel
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Daniel wrote:
I've been searching the net and Google news groups for a preg_match
expression that will return true on strings containing (uppercase and
lowercase) characters of A-Z, 0-9 and for instance Swedish characters .
It should return false on strings containing stuff like -#%\"[]()=?&/.

The thing is, I don't want to specifically allow , I want a more
general rule in case other characters like or turn up. Is this possible
to do?

I've tried
preg_match("/^\w+$/", $string)
and
preg_match("/^[[:alpha:]]+$/", $string)

but both returns false on everything except a-z A-Z.

I'm going to use it to test a receiver's name ($to_name) before putting it
in an e-mail header like "$to_name <$to_email>"; The names are entered in a
text field by my users and I want to test the name so it won't mess up the
e-mail header causing the e-mail to fail.

Any help would be greatly appreciated. Thank you.

Daniel

<quote source="RFC2822">
Note: This standard specifies that messages are made up of characters
in the US-ASCII range of 1 through 127. There are other documents,
specifically the MIME document series [RFC2045, RFC2046, RFC2047,
RFC2048, RFC2049], that extend this standard to allow for values
outside of that range. Discussion of those mechanisms is not within
the scope of this standard.
</quote>

So, according to this standard those characters you want to include in
the header part of your email are invalid :)
Anyway, I think it should work if you

<?php setlocale(LC_ALL, 'se_SE'); ?>
I have no idea about the correct locale string ('se_SE') for you.
--
..sig
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.