regex problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

faust
New php-forum User
New php-forum User
Posts: 109
Joined: Thu May 03, 2012 7:22 am

regex problem

Postby faust » Sat Jun 08, 2013 12:37 am

Hey guys, I really really suck at regex but I need one asap. The rules are:
- can contain only alphanum chars and underscore;
- must begin and end with a letter (not underscore or number);
- no spaces;

I need this to validate a field. Thanks, cheers ^_^

paintitblack
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 17, 2014 8:53 pm

Re: regex problem

Postby paintitblack » Mon Feb 17, 2014 9:26 pm

This should do it:

Code: Select all

^[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z]$


Note that this requires your data field to be at least two characters long.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests

cron