Page 1 of 1
Regular Expression Pattern Problem
Posted: Sun Apr 01, 2007 2:00 am
by CyberSpatium
I am having a heck of a time finding a regular expression pattern that works for a simple text string. i have a form field where users enter their name. if can be just their first name, first and last name, or just a nickname (max length is 30 characters).
I am trying to use ereg_match() to verify it is in the correct format. but I have tried pattern after pattern and I cannot get one to work.
any help would be greatly appreciated.
CyberSpatium
Posted: Sun Apr 01, 2007 3:05 am
by timvw
And what exactly would the pattern be? (Not in RE but in first five characters are only a,b,c and so on...) Simply restricting the length to be between 1 and 30 is as simple as: ^.{1,30}$ (strlen seems more appropriate for this task)
Posted: Sun Apr 01, 2007 4:39 am
by CyberSpatium
well, for security reasons, i am checking it to maker sure that only text has been submittted by the form, nothing else. so, the only thing allowed to be submitted text and a space, and that is what i am trying to limit it to with this pattern, but I have not been able to get one to work.
thx
cyberspatium
Posted: Sun Apr 01, 2007 5:28 am
by Kieran Huggins
This should work, but it's not perfect - you'll likely want to give it some more thought and some fine tuning.
play here:
http://www.cuneytyilmaz.com/prog/jrx/
Re: Regular Expression Pattern Problem
Posted: Sun Apr 01, 2007 5:45 am
by stereofrog
CyberSpatium wrote:I am having a heck of a time finding a regular expression pattern that works for a simple text string. i have a form field where users enter their name. if can be just their first name, first and last name, or just a nickname (max length is 30 characters).
I am trying to use ereg_match() to verify it is in the correct format. but I have tried pattern after pattern and I cannot get one to work.
any help would be greatly appreciated.
CyberSpatium
You have to define "name" more exactly. Are names like "O'Malley-Finkel-Harris-Smith" allowed? Is "^%&^%@#" a valid nickname?
[a-zA-Z ]{1,30}
This will match, among others, the string of 30 spaces.
Posted: Sun Apr 01, 2007 7:10 am
by CyberSpatium
the posts will be in this format:
firstname lastname
firstname
lastname
Firstname Lastname
Firstname
Lastname
nickname
Nickname
thx,
cyberspatium
Posted: Sun Apr 01, 2007 10:21 am
by timvw
So you don't want Tim O'Reilly as a customer?
Posted: Sun Apr 01, 2007 10:31 am
by CyberSpatium
true, did not think of that
Posted: Mon Apr 09, 2007 3:53 am
by kaisellgren
And what about non-English alphabets?
Kimi Räikkönen
Mika Häkkinen