Main Page
 The gatekeeper of reality is
 quantified imagination.

Stay notified when site changes by adding your email address:

Your Email:

Bookmark and Share
Email Notification
jsCommon Validation [Go Back]
The following will return false until the duplicate 'a' character is removed:


The following will return false until a valid email address is entered:


The following will return false until a valid phone number is entered (() - + 0-9 allowed):


The following will return false until a valid zipcode is entered (- 0-9 allowed):


The following will return false until only alphabetic characters are present (a-z A-Z allowed):


The following will return false until only number characters are present (0-9 allowed):


The following will return the string with all leading whitespace removed:


The following will return the string with all trailing whitespace removed:


NOTE: You can download the script from the main javascript page.

Other Useful Functions:
		function txtAlphaNumericFilter(data) {
			/* This function ensures that only alpha-numeric characters, dashes and whitespace are present */
			data = data.replace(/^\s+|\s+$/, '');
			data = data.replace(/[^a-zA-Z0-9\-\s]/g, '');
			return data;
		}
		function txtRemoveWhitespace(data) {
			/* This function removes leading and trailing whitespace */
			data = data.replace(/^\s+|\s+$/, '');
			return data;
		}
		function txtSwapWhitespace(data) {
			/* This function swaps out whitespace with a dash and also converts case to lower */
			data = data.replace(/\-\-/g, '-');
			data = data.replace(/\s+/g, '-');
			data = data.toLowerCase();
			return data;
		}
		function txtStringCap(data) {
			/* Capitalize the first letter of each word */
			return data.toLowerCase().replace(/\b./g, function(a) { return a.toUpperCase(); });
		}
		function txtNumbersAndCommas(data) {
			/* This function filters out everything except for numbers and commas */
			data = data.replace(/[^,0-9]/g, '');
			return data;
		}


Here's an extra function to try out. Ever had to deal with a copy-n-paste from a word document or PDF where quotes end up slanted and usually result in a strange a character in their place? The javascript below filters out slanted quotes into something standard.

function txtFilter_quotes(data) {
    /* Slanted quotes can cause chaos.  Compensate for it. */
    var pamperTxt = "";
    for (z = 0; z < data.length; z++) {
        var holdme = data.charAt(z);
        var holdmeCharCode = holdme.charCodeAt(0);
        if (holdmeCharCode == 8216) { /* Slanted left single-quote */ pamperTxt = pamperTxt + "'"; }
        else if (holdmeCharCode == 8217) { /* Slanted right single-quote */ pamperTxt = pamperTxt + "'"; }
        else if (holdmeCharCode == 8218) { /* Slanted low single-quote */ pamperTxt = pamperTxt + "'"; }
        else if (holdmeCharCode == 8220) { /* Slanted left double-quote */ pamperTxt = pamperTxt + "\""; }
        else if (holdmeCharCode == 8221) { /* Slanted right double-quote */pamperTxt = pamperTxt + "\""; }
        else if (holdmeCharCode == 8222) { /* Slanted low double-quote */ pamperTxt = pamperTxt + "\""; }
        else { pamperTxt = pamperTxt + holdme; }
    }
    return (pamperTxt);
}
About Joe