Solved

HTML5 and Regexp question

Posted on 2014-03-19
7
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

752 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