Javascript examples for String Operation:String Replace
Allow only letters and spaces with string replace and regex
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//from w w w. j av a 2 s . c o m var x = "foo foo".replace(/^[a-z\s]*$/, "XXX"); console.log(x); var x = "foo|foo".replace(/^[a-z\s]*$/, "XXX"); console.log(x); var x = "foo foo".replace(/^[a-z\s]*$/, "XXX"); console.log(x); var x = "foo 543foo".replace(/^[a-z\s]*$/, "XXX"); console.log(x); }); </script> </head> <body> </body> </html>