Announcement

Collapse
No announcement yet.

example code for cleaning messy user details

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    example code for cleaning messy user details

    this code, i thought i'd share, disallows the user typing of anything that isnt either a letter, caps and lowercase, or numbers. this,wes needed by us, to ensure the database was searchable through an external app i am writing, even though people tend to put crazy things in the fields sometimes.

    example page follows:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>scripty goodness</title>
    </head>
    
    <body>
    <!-- function i knocked up to strip bad mouth words -->
    <script type="text/javascript">
    	function stripanddanceforgabriel(numString) {
    		var re = new RegExp("[^0-9a-zA-Z]", "g");
    		return numString.replace(re, "");
    	}
    </script>
    
    <!-- example form that makes it work -->
    <form id="form1" name="form1" method="post" action="">
      <label>test input
      <input type="text" name="textfield" onkeyup="this.value = stripanddanceforgabriel(this.value)"/>
      </label>
    </form>
    <p>try typing anything but letters and numbers ;o)</p>
    </body>
    </html>
Working...
X