• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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!
0
zack4x4
Asked:
zack4x4
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
käµfm³d 👽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 BaldwinFixer of ProblemsCommented:
According to this page http://www.sitepoint.com/html5-form-validation/ , all you should need in the 'pattern' attribute is "[G]".
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now