Changes

Removing Special Characters

36 bytes added, 14:58, 14 July 2014
See Also
{{JavaScript Syntax}}
The following technique can be used to prevent a user from entering special characters in [[Custom Fields]].<br>
Include the following code in the '''HTML Tag box''' of the [[Custom Fields|custom field]] you wish to restrict:
onchange="javascript:this.value=this.value.replace(/['''''Search Expression''''']/'''flag''',' '''New String''' ');"
where
1. To remove all characters that aren't part of the basic Latin alphabet and 0-9 (such as . , & ; : ~ ! @ # $ % ^ & * ( ) + " ' <u>including the space key</u>) and immediately replace them with an underscore (_):
onkeyup="javascript:this.value=this.value.replace(/[\W]/g,'_');"
2. The following code will look for # [ $ ] and \ and replace them with an underscore (_) once the user has clicked away from the field:
onchange="javascript:this.value=this.value.replace(/[#[$\]\\@]/g,'_');"
'''Note''': if you also want to replace double quotes you must omit the double quotes around the javascript statement:
3. To restrict user to only enter Integers write this code in the HTML tag box:
:''<nowiki>onkeyup="javascript:this.value=this.value.replace(/[\D]/g,'');"</nowiki>''
==See Also==
* [[Ssescape|ssEscape]]
[[Category:Custom Fields]][[Category:JavaScript]]
8,849
edits