Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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

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
breeze351
Asked:
breeze351
  • 2
  • 2
1 Solution
 
Michael FowlerSolutions ConsultantCommented:
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
 
breeze351Author Commented:
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
 
Michael FowlerSolutions ConsultantCommented:
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
 
breeze351Author Commented:
Got it.
Thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now