JamesBrian
asked on
Validate input in textbox
Hi,
in a textbox, I want users to input numbers, delimited by a ' ; '
They need to input a 7digit number, then the ' ; ' and if needed, the next 7 digit number and so on
How do I do that?
in a textbox, I want users to input numbers, delimited by a ' ; '
They need to input a 7digit number, then the ' ; ' and if needed, the next 7 digit number and so on
How do I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well the code I post it it works this way:
Valid inputs:
1234567
1234567;1234567
1234567;1234567;1234567
Invalid inputs;
1234567;
1234567;Addaaa;
123;
etc
I think it's not practical to force the user to add always the last ";" ... but may be required :)
Valid inputs:
1234567
1234567;1234567
1234567;1234567;1234567
Invalid inputs;
1234567;
1234567;Addaaa;
123;
etc
I think it's not practical to force the user to add always the last ";" ... but may be required :)
ASKER
Sorry, but I forgot to mention that the 7 digits MUST be numerical...
Have you tried my function ?
ASKER
@jpaulino:
No , I have'nt, but Regular Expressions seem the logical way to do this....
No , I have'nt, but Regular Expressions seem the logical way to do this....
That's your decision ...
ASKER
@fernandosoto
Hi,
this works fine, but only for 1 '7d+;"
Entering 1234567;7654321;8523695;45 6852 returns an error. And that is what I was looking for
Hi,
this works fine, but only for 1 '7d+;"
Entering 1234567;7654321;8523695;45
Well my solution works fine but that's you call!
I only don't understand why you want to use regex ... because it's slower or because it sounds better.
I only don't understand why you want to use regex ... because it's slower or because it sounds better.
ASKER
because I had made up my mind to use the REGEX solution for its clean and ' much fewer lines to code ' way of coding a complex thing.Compare your solution (which works fine, I do not argue that) with the REGEX solution.
Why would a REGEX be slower ????
Apart from that...code just needs to work, not ' sound ' better.......
Why would a REGEX be slower ????
Apart from that...code just needs to work, not ' sound ' better.......
Of course that in this simple validation the speed is not a point but just for your information I have made a test with only 10000 repetitions (on a loop and using a stopwatch) using both methods. Here's the results:
(values in miliseconds)
Code: 243
Code: 244
Code: 243
Code: 241
Code: 242
Code: 243
Regex:417
Regex:425
Regex:419
Regex:421
Regex:416
Regex:421
I also use regex but for this I didn't found really necessary. But this is just my opinion :)
Good luck
(values in miliseconds)
Code: 243
Code: 244
Code: 243
Code: 241
Code: 242
Code: 243
Regex:417
Regex:425
Regex:419
Regex:421
Regex:416
Regex:421
I also use regex but for this I didn't found really necessary. But this is just my opinion :)
Good luck
Hi JamesBrian;
To have either a semicolon or no semicolon at the end of the list of digits change the regex pattern from this,
"^(\d{7};)+$", to this, "^(\d{7}?)+$".
Fernando
To have either a semicolon or no semicolon at the end of the list of digits change the regex pattern from this,
"^(\d{7};)+$", to this, "^(\d{7}?)+$".
Fernando
Open in new window