d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Regular Expressions Question > Php
Add Reply New Topic New Poll
Member
Posts: 5,299
Joined: Jul 4 2009
Gold: 2,632.57
Nov 7 2014 01:26pm
I have to validate some user input:
A city should start with an uppercase letter followed by one or more lowercase letters, uppercase letters, or periods (.).

What I have is:
/^[A-Z][A-Za-z\.]\+/
preg_match('/^[A-Z][A-Za-z\.]\+/', $_POST['myCity'])

But it's not working, nothing I enter matches the pattern.
Any help is appreciated
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 7 2014 04:58pm
iirc if you start with ^ you have to end with $, otherwise it's treated as "not" operator?

you should use some kind of regex test site. here's the first off google

http://www.phpliveregex.com/

tips for regex: start with a match (eg: starts with upper case), then slowly add each new criteria.

This post was edited by carteblanche on Nov 7 2014 04:59pm
Go Back To Homework Help Topic List
Add Reply New Topic New Poll