Difference between revisions of "Removing Special Characters"

From SmartWiki
Jump to: navigation, search
m
Line 1: Line 1:
To prevent a user from entering certain special characters in designated form fields.
+
To prevent a user from entering special characters in designated form fields.
  
 
Write the following code in Javascript box of a Custom field of type Special-Browser Script:
 
Write the following code in Javascript box of a Custom field of type Special-Browser Script:

Revision as of 09:24, 24 April 2009

To prevent a user from entering special characters in designated form fields.

Write the following code in Javascript box of a Custom field of type Special-Browser Script:

var r={'special':/[\W]/g}
function valid(o,w){
  o.value = o.value.replace(r[w],'');
}

Write the following code in the HTML Tag box of the custom field:

onkeyup="valid(this,'special')" onblur="valid(this,'special')"

Note: this can be extended to check for double quotes or single quotes or only for integer numbers.