HTML5 and Regexp question

Hi All - I have an easy question I can't seem to find an answer for.  I have an input box that accepts 1 character.  I want it to validate "G" only.   I've tried the following:

/^[G]$/i

Open in new window

and
^[G]/

Open in new window


Help!
Thanks!
LVL 4
zack4x4Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
käµfm³d 👽Connect With a Mentor Commented:
If a capital G is the only letter you want to validate, then simply remove the lowercase I from the from the end of the first example.
0
 
Terry WoodsIT GuruCommented:
You may like to post some code if @kaufmed's suggestion doesn't work.
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
According to this page http://www.sitepoint.com/html5-form-validation/ , all you should need in the 'pattern' attribute is "[G]".
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Terry WoodsIT GuruCommented:
Quick question: if you know it's G, do you really need to ask for it?

Also, I don't think you need the square brackets. A pattern of just G should work. The ^ and $ are implied, according to the page at Dave Baldwin's link.
0
 
zack4x4Author Commented:
Hi - Unfortunately none of that worked. :(

<tr><td class="text-bold" align="right">Tax Code:</td><td class="text-bold"><input onkeypress="return handleEnter(this, event);" style="text-transform: capitalize;" type="text" size=10 maxlength=1 class="DefaultEntry" id="taxcode" name="taxcode" pattern="G" value="<? if ($process == "") { print "G"; } else { print $_POST['taxcode']; } ?>"> (G: GST / Empty for No GST)</td></tr>

Open in new window

0
 
zack4x4Author Commented:
Hi All - I figured it out - when I looked at the submitted it data it was submitting as a lowercase g.  So once I added [gG] everything is working now.  Thanks for the help!
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, thanks for the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.