1  /**
     2   * com.sekati.validate.StringValidation
     3   * @version 1.0.5
     4   * @author jason m horwitz | sekati.com
     5   * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8  
     9   import com.sekati.utils.StringUtils;
    10  
    11  /**
    12   * String Validation methods for form fields
    13   * @see {@link com.sekati.utils.StringUtils}
    14   */
    15  class com.sekati.validate.StringValidation {
    16  
    17  	/**
    18  	 * validate a string as a valid email address
    19  	 * @param str (String)
    20  	 * @return Boolean
    21  	 */
    22  	public static function isValidEmail (str:String):Boolean {
    23  		return ((str.length < 6) || (str.indexOf ("@") < 1) || (str.length - (str.indexOf ("@")) < 5) || (str.indexOf ("@") != str.lastIndexOf ("@")) || (str.length - (str.lastIndexOf (".")) < 3) || (str.length - (str.lastIndexOf (".")) > 5) || (Math.abs ((str.indexOf ("@")) - (str.indexOf ("."))) == 1) || (str.indexOf (" ") != -1)) ? false : true;
    24  	}
    25  	
    26  	/**
    27  	 * validate a string begins with "http://"
    28  	 * @param str (String)
    29  	 * @return Boolean
    30  	 */
    31  	public static function isURL (str:String):Boolean {
    32  		return (str.substring (0, 7) == "http://" || str.substring (0, 8) == "https://");
    33  	}		
    34  
    35  	/**
    36  	 * validate if a strings contents are blank after a safety trim is performed
    37  	 * @param str (String)
    38  	 * @return Boolean
    39  	 */
    40  	public static function isBlank (s:String):Boolean {
    41  		var str:String = StringUtils.trim (s);
    42  		var i:Number = 0;
    43  		if (str.length == 0) {
    44  			return true;
    45  		}
    46  		while (i < str.length) {
    47  			if (str.charCodeAt (0) != 32) {
    48  				return false;
    49  			}
    50  			i++;
    51  		}
    52  		return true;
    53  	}
    54  
    55  	/**
    56  	 * validate if a string is composed entirely of numbers
    57  	 * @param str (String)
    58  	 * @return Boolean
    59  	 */
    60  	function isNumeric(str:String):Boolean {
    61  		var len:Number = str.length;
    62  		for (var i:Number = 0; i < len; i++) {
    63  			var code:Number = str.charCodeAt(i);
    64  			if (code < 48 || code > 57) {
    65  				return true;
    66  			}
    67  		}
    68  		return false;
    69  	}
    70  
    71  	/**
    72  	 * check if address is a Post Office Box
    73  	 * @param address (String)
    74  	 * @return Boolean
    75  	 */
    76  	function isPOBox(address:String):Boolean {
    77  		var look:Array = ["PO ", "P O", "P.O", "P. O",  "p o", "p.o", "p. o", "Box", "Post Office", "post office"];
    78  		var len:Number = look.length;
    79  		for (var i:Number = 0; i < len; i++) {
    80  			if (address.indexOf(look[i]) != -1) {
    81  				return true;
    82  			}
    83  		}
    84  		return false;
    85  	}
    86  	
    87  	private function StringValidation(){
    88  	}
    89  }