Solved

How do I set up an input (text pattern) for a dollar field

Posted on 2015-01-12
4
142 Views
Last Modified: 2015-02-02
I have a page where I'm getting data from a previous page.  The field is a monthly rental and therefor is #####.##.  The data being passed is "250.00".  I originally had the field as a numeric but that displays "250".  I've tried several different "patterns" that i googled but they didn't work as advertised.

The code that I'm currently running is:

echo '<input type="number" pattern = "0.00-99999.99 {8}" title = "Enter a dollar amount without commas" name="$PSF" size = "8" min = "0.00" max = "99999.99" value="';
echo $work;
echo '" maxlenghth="8" step = "0.01">';

The source code in the browser reads as:

<input type="number" pattern = "0.00-99999.99 {8}" title = "Enter a dollar amount without commas" name="$PSF" size = "8" min = "0.00" max = "99999.99" value="250.00" maxlenghth="8" step = "0.01">

Thanks for the help
Glenn
0
Comment
Question by:breeze351
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 40545445
Try using type text with a regex pattern

input type="text" pattern="^\d*(\.\d{2}$)?"

Here are some examples of dealing with this problem.
http://jsfiddle.net/NfMQ7/178/
0
 

Author Comment

by:breeze351
ID: 40554265
That worked.  But how do I let the user add commas to the field?  Is there a site that I can learn how the "pattern" works?
Glenn
0
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40556588
The pattern in this case is a regular expression or regex and there are lots a good sites with tutorials on this subject eg http://regexone.com/

Here is a regex that allows for currency

^([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(\.[0-9][0-9])?$

Open in new window

http://regexlib.com/Search.aspx?k=currency
0
 

Author Closing Comment

by:breeze351
ID: 40584731
Got it.
Thanks
0

Featured Post

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.

Join & Write a Comment

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 Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

706 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

14 Experts available now in Live!

Get 1:1 Help Now