> Via regular expressions, how do I replace characters in a string with
> ""(nothing) if they aren't in an array of allowed characters?
>
> var allowed = ["x","y"," "];
>
> var string = "xyz w yz"; - replace everything not in allowed array.
<input type="text" value="zxujh yjhg xzhgt" onblur="
var allowed = [ 'x', 'y', ' '];
var re = new RegExp( '[^' + allowed.join('') + ']', 'g' );
alert( this.value.replace( re, '') );
">

Signature
Rob
cymrio@yahoo.com - 30 Jul 2005 13:18 GMT
> What RobG wrote:
Excellent, thanks Rob.
RobG - 31 Jul 2005 00:44 GMT
>>What RobG wrote:
>
> Excellent, thanks Rob.
The use of an array is not necessary, the allowed characters can be a
simple string:
var allowed = 'xy ';
var re = new RegExp( '[^' + allowed + ']', 'g' );

Signature
Rob