Changes

Removing Special Characters

296 bytes added, 21:23, 30 April 2009
no edit summary
==Procedure:==
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''' ');"
==Options==
For Search Expression you can use
* \W = Matches any character that is '''not''' a word character from the basic Latin alphabet, an integer, or the underscore. Equivalent to [^A-Z a-z 0-9 _]
* \w = Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_]
* \D = Matches any character that is ''\' not' = single quotes* '\" ' = double quotesan integer.* \d = Matches a digit character in the basic Latin alphabetall integers. Equivalent to [0-9]
* \0 = NULL character
* \s = Matches a single white space character
* [xyz]= A character set. Matches any one of the enclosed characters. You can specify a range of characters by using a hyphen. For example, [abcd] is the same as [a-d]. They match the 'b' in "brisket" and the 'c' in "ache".:* Any individual character can be specified within the square brackets except double quote " which has special meaning.:* If you wish to include the backslash \ or closing square bracket ] you must precede them with a backslash:  For Flags Flag the following options are available:* g = global match
* i = ignore case
Using ''onChange'' will replace the characters as soon as the user clicks in a field other than the away from current field, or hits saveSave.<br>
Using ''onKeyup'' will replace the characters as soon as they are typed.
==Examples==
'''1. To remove all characters that aren't part of the basic Latin alphabet and 0-9 ('''such as . , & ; : ~ ! @ # $ % ^ & * ( ) + " ' and <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 (_) actively while typing once the user has clicked away from the text. field:<pre>onkeyup onchange="javascript:this.value=this.value.replace(/[#[$\]\\W@]/g,'_');"<'''Note''': if you also want to replace double quotes you can omit the double quotes around the javascript statement::''onchange=javascript:this.value=this.value.replace(/['@#&"]/pre>g,'_');'' 
3. To restrict user to only enter Integers write this code in the HTML tag box:
'''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 onkeyup="javascript:this.value=this.value.replace(/['"&\D]/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]]
0
edits