Python code to use a regular expression to make sure a string is alphanumeric plus . - _
Posted
by Warlax
on Stack Overflow
See other posts from Stack Overflow
or by Warlax
Published on 2010-03-25T21:51:53Z
Indexed on
2010/03/26
7:33 UTC
Read the original article
Hit count: 460
Hi,
I looked and searched and couldn't find what I needed although I think it should be simple (if you have any Python experience, which I don't).
Given a string, I want to verify, in Python, that it contains ONLY alphanumeric characters: a-zA-Z0-9
and .
_
-
examples:
Accepted:
bill-gates
Steve_Jobs
Micro.soft
Rejected:
Bill gates
-- no spaces allowed
[email protected]
-- @ is not alphanumeric
I'm trying to use:
if re.match("^[a-zA-Z0-9_.-]+$", username) == True:
But that doesn't seem to do the job...
© Stack Overflow or respective owner