Solved

HTML5 and Regexp question

Posted on 2014-03-19
7
197 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Title # Comments Views Activity
Can't get container centered 4 25
key press alert 2 32
edit .asp files 5 32
html input 8 44
Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
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.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 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