Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
basic Regex for a name field
Old 03-16-2009, 08:58 PM basic Regex for a name field
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
I was using this:

Code:
[^a-zA-Z][p{Zs}]
To validate a name field, it basically just has to consist of letters and spaces. But for some reason it would fail if the first letters of each word weren't capitalized!

Does anyone know how I can fix this?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is online now
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 03-16-2009, 09:20 PM Re: basic Regex for a name field
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Not sure what the purpose of your second [] section is, but try

Code:
[^a-zA-Z]+[p{Zs}]
or
Code:
[^a-zA-Z]+[p{Zs}]+
Again, that's depending on what the second part is for.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 03-16-2009, 11:45 PM Re: basic Regex for a name field
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
You should take a look at this cheat sheet, or this one.
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-18-2009, 01:46 PM Re: basic Regex for a name field
Skilled Talker

Posts: 84
Trades: 0
If you are using a linux box you can try regex with pcretest command
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
- 1-888-869-HOST(4678)
Award winning Managed Hosting -
Please login or register to view this content. Registration is FREE

Managed Dedicated Servers. Reseller Discounts. 24/7 Impressive Tech Support
HivelocityDD is offline
Reply With Quote
View Public Profile
 
Old 03-19-2009, 05:34 PM Re: basic Regex for a name field
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Thanks
Quote:
Originally Posted by JeremyMiller View Post
Not sure what the purpose of your second [] section is, but try

Code:
[^a-zA-Z]+[p{Zs}]
or
Code:
[^a-zA-Z]+[p{Zs}]+
Again, that's depending on what the second part is for.
I think the second part was to match a space character, but it was quite a while ago so I can't really remember why I did it like that!

For some reason this bit of code evaluates to true
Code:
var regex = new RegExp ('[a-zA-Z]');

alert (regex.test ('f4'));
I thought that a regex such as that would only allow uppercase and lowercase letters; nothing else. But the string 'f4' results in a match! Im not too sure what I'm doing from though? I presume I need a '\s' in there somewhere to match a space character aswell.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is online now
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 03-20-2009, 04:27 PM Re: basic Regex for a name field
kline11's Avatar
SearchBliss Web Tools

Posts: 1,726
Name: John
Location: USA
Trades: 0
Try this:
Code:
 ^a-zA-Z'`-´\s{1,40}$
Validates a name. Allows up to 40 uppercase and lowercase characters and a few special characters that are common to some names.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by kline11; 03-20-2009 at 04:28 PM..
kline11 is offline
Reply With Quote
View Public Profile
 
Old 03-22-2009, 02:23 PM Re: basic Regex for a name field
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Quote:
Originally Posted by kline11 View Post
Try this:
Code:
 ^a-zA-Z'`-´\s{1,40}$
Validates a name. Allows up to 40 uppercase and lowercase characters and a few special characters that are common to some names.
Thanks!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is online now
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 03-22-2009, 02:28 PM Re: basic Regex for a name field
kline11's Avatar
SearchBliss Web Tools

Posts: 1,726
Name: John
Location: USA
Trades: 0
Quote:
Originally Posted by KkillgasmM View Post
Thanks!
No problem, just let me know how it works out for you.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
kline11 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to basic Regex for a name field
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37432 seconds with 12 queries