# Editing a textbox for numeric

I need to edit a textbox for numeric and may contain up to 1"." (decimal pt).    I want to check for one decimal that could be anywhere  in the 15 characters.  Must be numeric except for the decimal.  Can only have 1 decimal max but does not have to have 1.  Any number of characters up to 15.

Valid                                                                            invalid
1111111111.0001                                                     100.1.30
111111111                                                                1abc200
1.000000                                                                   10000000000000000000000.000001
Programming

Last Comment
silemone

8/22/2022 - Mon
silemone

(*[0-9A-Za-z]+\.[[0-9A-Za-z][0-9A-Za-z]*){3, 15}
use in a custom validator
silemone

(*[0-9A-Za-z]+\.[0-9A-Za-z][0-9A-Za-z]*){3, 15}
use in a custom validator

oops...Regular expression that states any amount of letters that have at least one digit or letter (alphanumeric in front, followed by a period, followed by at least one alphanumeric and therefore you must have at least  3 characters and up to 15.
silemone

(*[0-9A-Za-z]+[.]{0,1}[0-9A-Za-z][0-9A-Za-z]*){3, 15}
use in a custom validator

Just read your statement clearer...this is same as above except there can be 1 or less periods
silemone

my regular expression is wrong...i'm trying to figure this one out.
garyinmiami2003

It does not have to be just 1 edit.  Must catch anything non numeric and allow only "."
silemone

yep and that's what regular expressions are good for, pattern matching...basically the patterns are

1
11
111
1a1  up to fifteen characters
but when the decimal comes into play, that when the problem occurs because that must at least one alphanumeric in front of the decimal and i would think one after....i.e. pattern if there's a decimal:
x.x   can't be .x   or x.     where x = a-z, 0-9, etc.

problem is i can make a regular expression for this but it will be pretty long... because you have to consider when there's not a set number of decimals in front of the decimal nor in back.  so you have a lot of cases to consider...  what programming language are you using by the way?
.....
garyinmiami2003

Well how about a try catch to see if the textbox is decimal:

Try
convert.todecimal(txtmBox1.text)
catch...
silemone

that would actually work and you could set the text box length to 15.
silemone

well, i'm sorry...is decimal wouldn't work because your input will be alphanumeric...
silemone

i'm actually doing a programs to work with the regular expression.  Another option you have to separate the string, but that's more code than needed...but as a last result that will be the way to go.
silemone

here's the regular expression: ^[0-9A-Za-z]{1,15}([.]{0,1}[0-9A-Za-z]{1,13})*\$
silemone

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
silemone

oh...and remove the * that's before the \$
silemone

^[0-9A-Za-z]{1,15}([.]{0,1}[0-9A-Za-z]{1,13})\$

remove the * before the \$ in the example code too when testing it.