Solved

HTML5 and Regexp question

Posted on 2014-03-19
7
187 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 74

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 82

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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 82

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
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 …

708 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

21 Experts available now in Live!

Get 1:1 Help Now