Login
Register
Questions
Unanswered
Tags
Users
Ask a Question
Tips
Sawtooth Software Home
Most popular tags
cbc
lighthouse-9
acbc
ssi-web
ssi-web-8
maxdiff
cbc-hb
grid-question
javascript
constructed-list
unverified-perl
ssi-web-7
free-format
skip-logic
alternative-specific-design
select-question
willingness-to-pay
choice-simulator
cbc-latent-class
quota-control
acbc-hb
mbc
conditional-pricing
smrt
pass-in-fields
Have an idea?
Visit
Sawtooth Software Feedback
to share your ideas on how we can improve our products.
Numeric with comma
This solution has been helpful for me, however I am still missing something. I need to restrict other specify boxes as well as grid rows to only allow numbers and commas (they are various questions that require a currency response). When I try to implement the regex similar to the one that allows optional decimal points (replacing with comma), the question allows both letters and numbers, and will only show the error message if there are no numbers.
How should I adjust the JavaScript to allow respondents to put in only numbers and commas?
var resp = SSI_GetValue('[% QuestionName() %]_3_other');
var regex = /([0-9]+,?[0-9]*)|([0-9]*,?[0-9]+)/;
if (resp && !regex.test(resp)) {
strErrorMessage = 'Error.';
}
related to an answer for:
Default other/specify option text box to accept only numeric values
asked
Oct 17, 2017
by
anonymous
Your comment on this question:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
[captcha placeholder]
To avoid this verification in future, please
log in
or
register
.
Your solution to the original question
Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or
register
.
1 Answer
0
votes
This regular expression will allow only numerical characters and commas:
/^[0-9,]*$/
This more complex regex will allow only numeric characters with commas every three characters from the right:
/^[0-9]{1,3}(,[0-9]{3})*$/
answered
Oct 17, 2017
by
Zachary
Platinum
(
202,850
points)
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
[captcha placeholder]
To avoid this verification in future, please
log in
or
register
.
...