VB icon

Handy Form Utility

Email
Submitted on: 1/5/2015 1:20:00 PM
By: Shrike (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 828
 
     This helps you verify all kinds of forms using regular expressions.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Handy Form Utility
' Description:This helps you verify all kinds of forms using regular expressions.
' By: Shrike (from psc cd)
'
' Returns:It simply gives you back TRUE OR FALSE for the user's input using regular expressions. But it's strict and.. well pretty handy stuff.
'
' Assumes:	'* EMAIL		=	xyxyxy.xyxyxy@xyxy.xyx
	'* POSTAL		=	yyyy+
	'* NAME			=	xxxxxx xxxxx
	'* STREET		=	xxxxxxx yy
	'* COUNTRY		=	(all countries in ENGLISH only)
	'* ALPHASTRING	=	xxxxx x xx xx xx x xxx
'**************************************

	FUNCTION frmCheck(strType,strCheck)
					DIM objRegExp
					SET objRegExp			=	NEW RegExp
					objRegExp.IgnoreCase	=	TRUE
	
					SELECT CASE strType
						CASE "email"		objRegExp.Pattern	=	"^([A-Za-z0-9_.]{3,15})\@(\w{3,15})\.(\w{3,15})$"
						CASE "postal"		objRegExp.Pattern	=	"^([0-9]{4,})$"
						CASE "name"			objRegExp.Pattern	=	"^([A-Za-z]{3,15})(\s)([A-Za-z]{3,15})$"
						CASE "street"		objRegExp.Pattern	=	"^([A-Za-z]{3,15})(\s)([A-Za-z0-9\/\.]{1,8})$"
						CASE "country"		objRegExp.Pattern	=	"^(Afghanistan|Albania|Algeria|Andorra|Angola|Anguilla|Antarctica|Antigua|Argentina|Armenia|Aruba|Ashmore|Australia|Austria|Azerbaijan|Bahamas|Bahrain|Baker|Baker Island|Barbados|Bassas|Bangladesh|Belarus|Belgium|Belize|Benin|Bermuda|Bhutan|Botswana|Bolivia|Bosnia|Bouvet|Bouvet Island|Brazil|British|Brunei|Bulgaria|Burkina|Burkina Faso|Burma|Burundi|Cambodia|Cameroon|Canada|Capeverde|Cape Verde|Cayman|Cayman Islands|Centralaf|Central African Republic|Chad|Chile|China|Christmas|Christmas Island|Cocos|Colombia|Comoros|Congo|Congodem|Cook|Costarica|Costa Rica|Cote|Cote D`Ivoire|Ivory Coast|Croatia|Cuba|Cyprus|Czechrep|Czech Republic|Denmark|Djibouti|Dominica|Dominican|Dominican Republic|Ecuador|Egypt|El Salvador|Equatorial Guinea|Eritrea|Estonia|Ethiopia|Falkland|Falkland Islands|Faroe|Faroe Islands|Fiji|Finland|France|French Guiana|French Polynesia|French Southern Territories|Fyrom|F.Y.R.O.M.|Gabon|Gambia|Gaza|Gaza Strip|Georgia|Germany|Ghana|Gibraltar|UK|Great Britain|Greece|Greenland|Grenada|Guadeloupe|Guam|Guatemala|Guernsey|Guinea|Guinea-Bissau|Guyana|Haiti|Heard|Heard & Mcdonald Islands|Honduras|Hongkong|Hong Kong|Hungary|Iceland|India|Indonesia|Iran|Iraq|Ireland|Israel|Italy|Jamaica|Japan|Jordan|Kazakhstan|Kenya|Kiribati|Korea|Korea South|Korea North|Kuwait|Kyrgyzstan|Laos|Latvia|Lebanon|Lesotho|Liechten|Liechtenstein|Liberia|Libya|Lithuania|Luxembourg|Macau|Madagascar|Malawi|Malaysia|Maldives|Mali|Malta|Marshall|Marshall Islands|Martinique|Mauritania|Mauritius|Mayotte|Mexico|Micronesia|Monaco|Moldova|Morocco|Mongolia|Montserrat|Mozambique|Myanmar|Namibia|Nauru|Nepal|Netherlands|Antilles|Netherlands Antilles|Caledonia|New Caledonia|Nicaragua|Niger|Nigeria|Niue|Norfolk|Norfolk Island|Mariana|Northern Mariana Islands|Norway|Oman|Pakistan|Palau|Palestine|Panama|Papua|Papua New Guinea|Paraguay|Peru|Philippines|Pitcairn|Pitcairn Islands|Poland|Portugal|Puertorico|Puerto Rico|Qatar|Reunion|Romania|Russian|Russian Federation|Rwanda|Kitts|Saint Kitts & Nevis|Lucia|Saint Lucia|Vincent|Saint Vincent |Marino|San Marino|Tome|Sao Tome & Principe|Saudi|Saudi Arabia|Senegal|Seychelles|Sierra|Sierra Leone|Singapore|Slovenia|Slovak|Slovak Republic|Solomon|Solomon Islands|Somalia|South Africa|Spain|Srilanka|Sri Lanka|Sthelena|St. Helena|Stpierre|St. Pierre & Miquelon|Sudan|Suriname|Svalbard|Svalbard & Jan Mayen Isl.|Swaziland|Sweden|Switzerland|Syria|Taiwan|Tajikistan|Tanzania|Thailand|Togo|Tokelau|Tonga|Trinidad|Trinidad & Tobago|Tunisia|Turkey|Turkmenistan|Turks|Tuvalu|Uganda|Ukraine|United Arab Emirates|UK|United Kingdom|USA|United States|Uruguay|Uzbekistan|Vanuatu|Vatican|Venezuela|Vietnam|Virgin Islands|Wallis|Western Sahara|Westbank|West Bank|Yemen|Yugoslavia|Zambia|Zimbabwe)$"
						CASE "alphastring"	objRegExp.Pattern	=	"^([A-Za-z\s]{1,255})$"
						CASE ELSE		
							 frmCheck	=	"False (invalid strType)"
							 EXIT FUNCTION
					END SELECT
					frmCheck			=	objRegExp.Test(cStr(strCheck))
	END FUNCTION
	Use : 
	
	IF frmCheck("email",strEmail) = TRUE AND frmCheck("country",strCountry) = TRUE THEN ...
	
	
	Try it simple with : 
	
	Response.Write frmCheck("email","blabla@bla.com")
	Response.Write frmCheck("country","zimbabwe")
	Response.Write frmCheck("name","jennifer lopez")
	Response.Write frmCheck("street","aspstreet 17a")


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.