Changes

Jump to: navigation, search

Removing Special Characters

8 bytes added, 12:48, 28 April 2009
no edit summary
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 . , & ; : ~ ! @ # $ % ^ & * ( ) + " ' and the space key''') and replace them with an underscore (_) actively while typing the text.
<pre>
onkeyup="javascript:this.value=this.value.replace(/[\W]/g,'_');"
</pre>
'''2. After user has entered text and clicked away from the field, the following code will look for quotes (" and ') and the ampersand (&) and replace them with an underscore (_).
<pre>
onchange="javascript:this.value=this.value.replace(/['"&]/g,'_');"
</pre>
'''3. To restrict user to only enter Integer numbers write this code in the HTML tag box.
<pre>
onkeyup="javascript:this.value=this.value.replace(/[^\d]/g,'');"
</pre>
[[Category:Custom Fields]][[Category:JavaScript Examples]]
Smartstaff
137
edits

Navigation menu