Solved

HTML5 and Regexp question

Posted on 2014-03-19
7
195 Views
Last Modified: 2014-03-20
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
Comment
Question by:zack4x4
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 39941352
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
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39941357
You may like to post some code if @kaufmed's suggestion doesn't work.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 39941454
According to this page http://www.sitepoint.com/html5-form-validation/ , all you should need in the 'pattern' attribute is "[G]".
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 39941469
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
 
LVL 4

Author Comment

by:zack4x4
ID: 39943213
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
 
LVL 4

Author Closing Comment

by:zack4x4
ID: 39943253
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39943408
You're welcome, thanks for the points.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now