close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How do I restrict a comma from a number validation?

Thread began 10/21/2009 5:00 am by RichGags | Last modified 10/21/2009 2:41 pm by Jimmy Wu | 3801 views | 3 replies |

RichGags

How do I restrict a comma from a number validation?

Ive got the client Validation toolkit checking a field on my form before submitting it to my credit card processor. I am getting an error back from my processor "Invalid XML" only if the user enters a number in the thousands with a comma.

How would I either strip the comma out, or make the message pop up "Dont put a comma in your number"?

Thanks!
Rich

PS: Here's my code...

on the button...

WAValidateNM(document.form1.chargetotal,'- Invalid Amount',1,20000,2,'','',',.',document.form1.chargetotal,0,true);


function...

function WAValidateNM(formElement,errorMsg,minLength,maxLength,allowDecimals,roundDecimals,reformatDecimals,punctuationMarks,focusIt,stopIt,required) {
var isValid = true;
var theThousand = punctuationMarks.charAt(0);
var theDecimal = punctuationMarks.charAt(1);
var theCheck = 11/10;
var trueDecimal = (String(theCheck).charAt(1));
var value = formElement.value;
var decimalIndex = value.length;
if (punctuationMarks.indexOf(trueDecimal)<0 && value.indexOf(trueDecimal)>=0) {
isValid = false;
}
if (value.lastIndexOf(theDecimal)>=0) {
decimalIndex = value.lastIndexOf(theDecimal);
}
while (value.indexOf(theThousand)>=0) {
decimalIndex = value.length;
if (value.lastIndexOf(theDecimal)>=0) {
decimalIndex = value.lastIndexOf(theDecimal);
}
if ((decimalIndex-(value.lastIndexOf(theThousand)+1))%3 != 0)
isValid = false;
value = value.substring(0,value.lastIndexOf(theThousand)) + value.substring(value.lastIndexOf(theThousand)+1);
}
if (trueDecimal != theDecimal) {
while (value.indexOf(theDecimal)>=0) {
value = value.substring(0,value.indexOf(theDecimal)) + trueDecimal + value.substring(value.indexOf(theDecimal)+1);
}
}
if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value=="")) {
for (var x=0; x<value.length; x++) {
if ((value.charAt(x)<0 || value.charAt(x) > 9) && (value.charAt(x) != " " && value.charAt(x) != "," && value.charAt(x) != ".")) {
isValid = false;
}
}
if (value == "") {
isValid = false;
}
var oldVal = String(value);
if (oldVal.indexOf(trueDecimal)>=0) {
while (oldVal.charAt(oldVal.length-1)=="0" || oldVal.charAt(oldVal.length-1) == trueDecimal) {
if (oldVal.charAt(oldVal.length-1) == trueDecimal) {
oldVal = oldVal.substring(0,oldVal.length-1);
break;
}
else oldVal = oldVal.substring(0,oldVal.length-1);
}
if (oldVal.indexOf(trueDecimal)==0)
oldVal = "0" + oldVal;
}
if (String(allowDecimals) !="" ) {
if (String(value).indexOf(".") > 0 && ((String(value).indexOf(".") + allowDecimals + 2 <= String(value).length) || allowDecimals == 0)) {
isValid = false;
}
}
value = parseFloat(value);
if (isNaN(value)) {
isValid = false;
}
else if (String(value).length!=String(oldVal).length && String(oldVal).substring(String(value).length+1).search(/^\.?0*$/) == -1 ) {
isValid = false;
}
else if ((String(minLength) != "" && minLength > value) || (String(maxLength) != "" && maxLength < value)) {
isValid = false;
}
}
if (!isValid) {
WAAddError(formElement,errorMsg,focusIt,stopIt);
}
else {
if (value != "") {
if (roundDecimals != "") {
value = Math.round(value*roundDecimals)/roundDecimals;
}
if (reformatDecimals != "") {
value = String(value);
if (value.indexOf(trueDecimal)<0)
value += trueDecimal;
if (value.indexOf(trueDecimal) < value.length - reformatDecimals) {
value = value.substring(0,value.indexOf(trueDecimal) + reformatDecimals + 1);
}
else {
while (value.indexOf(trueDecimal) > value.length - reformatDecimals - 1) {
value += "0";
}
}
}
}
if (trueDecimal != theDecimal) {
value = String(value);
while (value.indexOf(trueDecimal)>=0) {
value = value.substring(0,value.indexOf(trueDecimal)) + theDecimal + value.substring(value.indexOf(trueDecimal)+1);
}
}
if (roundDecimals != "" || reformatDecimals != "")
formElement.value = value;
}
}

Sign in to reply to this post

Jimmy Wu

What you can do is to apply a Restrict Content validation with Validation Toolkit and put the comma in the Don't allow, select includes in the dropdown and leave the replace with blank. This will check if there are any commas are entered into the form field.

Sign in to reply to this post

RichGags

Worked perfectly. Thanks.

Sign in to reply to this post

Jimmy Wu

Great to hear. If you run into any additional issues, feel free to make a new thread.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...