PDA

View Full Version : Text Box


jsmals
04-08-2004, 10:47 AM
I have a text box set up on a form so folks can input a numeric value which populates a database. Is there any way to force a five digit number with a period(.) and a two diget numeric to follow. So example; 12345.67 . I would like to force this and not allow users to type in more than the example above

Thank you

Jokerman
04-08-2004, 10:48 AM
Regular expressions can do it, I'm not the regex whiz though, so someone else will have to show the code for it.

-Tim

agent002
04-08-2004, 10:52 AM
whoops, I adviced you to post here although you probably want your server side script to check the value. Oh well, regular expressions look pretty much the same in all languages, both client side and server side. You could have a look at this (http://www.troubleshooters.com/codecorn/littperl/perlreg.htm) guide for Perl regular expressions, it should help you also if you use PHP or if you want a JavaScript to check it.

Willy Duitt
04-08-2004, 01:54 PM
/^(\d{5}\.\d{2})?$/

.....Willy

AaronCampbell
04-08-2004, 04:12 PM
Ok, regular expressions are VERY specific, so you gotta think about EXACTLY what you want.
This will force a number that is exactly 5 digits, a decimal, and 2 more.
'/^\d{5}\.\d{2}$/'

This is the same, but the first number cannot be a 0.
'/^[1-9]\d{4}\.\d{2}$/'

Also, if 5 and 2 are the Maximum amount of digits you want, but there can be less, or if the decimal is optional, it would change to something like this:
'/^\d{1,5}(\.[\d]{2})?$/'

Anyway, there is a great page that has a Regular Expressions Tutorial (http://dinki.mine.nu/word/regex/regex.php).

Hope that helps.


PS - If you need any help on HOW to implement Regular Expressions, it might be nice to know what language you plan on using.