<%LANGUAGE=VBSCRIPT%> <% '********************************************************************* 'CapsValid Capitalizaes the first letter and the first letter following a space (Chr(32)) 'of any given text string. '********************************************************************* Function CapsValid(Subject) Dim strInput, MyString2, x, fltr, fltrAsc, fltrCap,i strInput = Subject If strInput<>"" Then fltr = Left(strInput,1) fltrAsc = Asc(strInput) fltrCap = fltrAsc - 32 'You can now use chr(fltrCAP) as the capital letter MyString2="" For x=1 to Len(strInput) 'Read in first letter MyString2 = MyString2 & Right(Left(strInput,x),1) 'Check if first letter is capitalized If X=1 Then If (Asc(MyString2) > 91) Then MyString2 = Chr(fltrCap) End If End If 'This enforces the fisrt letter after a space (Chr(32)) is capitalized 'by looping through the lowercase letters and subtracting 32 to reflect 'thier capital ASCI values For i = 97 to 122 If Right(MyString2,2)= Chr(32)& Chr(i) Then MyString2 = Left(MyString2,Len(MyString2)-2) MyString2 = MyString2 & Chr(32)&Chr(i-32) End If Next Next 'Return the value CapsValid = MyString2 Else End If End Function '********************************************************************************** %> <% '********************************************************************************** 'Phone number formater (Compliments of ASP101.com) 'Takes a string on letters and numbers and converts them into a standard phone number '********************************************************************************** Dim Phone 'Format a given 10 digit phone number into standard phone number Function FormatPhoneNumber(strNumber) Dim strInput 'String that holds the number entered Dim strTemp 'Temporary String to hold our working text Dim strCurrentChar 'Var for storing each character for eval Dim I ' Looping variable 'Convert all characters to uppercase for consistency strInput=UCase(strNumber) 'Strip all characters except for the numbers themselves 'However we will also handle letters For I=1 to Len(strInput) strCurrentChar = Mid(StrInput, I, 1) 'Numbers 0 to 9 If Asc("0") <= Asc(strCurrentChar) and Asc(strCurrentChar) <=Asc("9") Then strTemp = strTemp & strCurrentChar End If 'Uppercase Chars (A-Z) If Asc("A") <= Asc(strCurrentChar) And Asc(strCurrentChar) <= Asc("Z") Then strTemp = strTemp & strCurrentChar End If Next 'Swap strTemp back to strInput for next set of validation strInput = strTemp 'Then clear strTemp StrTemp="" 'Remove the leading 1 If len(strInput)=11 and Left(strInput,1)="1"Then strInput = Right(strInput, 10) End If 'Error catch to make sure strInput is proper length now that 'we have finished manipulating it If Not Len(strInput)=10 Then 'Post error message such as... 'Err.Raise 1, "FormatPhoneNumber function", "The phone number to be formatted must be a valid 10 digit US phone number!" 'Response.Write "The phone number to be formatted must be a valid 10 digit US phone number!" 'Response.End 'Error="The phone number to be formatted must be a valid 10 digit US phone number! (From Function)" 'FormatPhoneNumer = Error %> <% Response.End End If 'If an error occurred, the formatting of the number should not continue. 'But if the number is proper, it will be formatted through the following... strTemp = "(" strTemp = strTemp & Left(strInput,3) 'Area Code strTemp = strTemp & ")" strTemp = strTemp & Mid(strInput, 4,3) 'Exchange strTemp = strTemp & "-" strTemp = strTemp & Right(strInput,4) 'Line 'Set the return value FormatPhoneNumber = strTemp End Function %> <% '********************************************************************************** 'ZIP CODE number formater (Modified version of Phone Number) 'Called with FormatZip(strNumber) '********************************************************************************** Function FormatZip(strNumber) Dim strInput 'String that holds the number entered Dim strTemp 'Temporary String to hold our working text Dim strCurrentChar 'Var for storing each character for eval Dim I ' Looping variable 'Convert all characters to uppercase for consistency strInput = strNumber 'Strip all characters except for the numbers themselves 'However we will also handle letters For I=1 to Len(strInput) strCurrentChar = Mid(StrInput, I, 1) 'Numbers 0 to 9 If Asc("0") <= Asc(strCurrentChar) and Asc(strCurrentChar) <=Asc("9") Then strTemp = strTemp & strCurrentChar End If Next 'Swap strTemp back to strInput for next set of validation strInput = strTemp 'Then clear strTemp StrTemp="" 'Error catch to make sure strInput is proper length now that 'we have finished manipulating it If Len(strInput)=5 Then FormatZip=strInput Else If Len(strInput)=9 Then strTemp = strTemp & Left(strInput,5) 'Primary Zip strTemp = strTemp & "-" strTemp = strTemp & Right(strInput,4) 'Extended Zip FormatZip = strTemp Else 'Post error message such as... 'Err.Raise 1, "FormatZip function", "The zip code to be formatted must be a valid 5 or 9 digit US zip code" 'Response.write "The zip code to be formatted must be a valid 5 or 9 digit US zip code" %> <% Response.End End If End If End Function %> <% '******************************************************************************* 'Duplicate Email validation check '********************************************************************************** Function ChkEmailDup(EMLEntered) 'Initialize variables to be used Dim rsCheckEML, NoDup 'Create a Recordset of all passwords Set rsCheckEML = Server.CreateObject("ADODB.recordset") With rsCheckEML .source="SELECT Email FROM Customer" .ActiveConnection ="DSN=LaundryCarts;" .open .movefirst End With 'Loop through the recordet looking for a match on the entered password NoDup=1 'Set NoDup to 1 (ON meaning the password is OK) 0 (Off if a duplicate is found, password fails test) Do While Not (NoDup=0 or rsCheckEML.EOF) 'stop checking recordset if 1 duplicate is found or at end of recordset NoDup=StrComp(EMLEntered,rsCheckEML("Email"),1) 'Compare Variable to fields in DB to determine if duplicate rsCheckEML.MoveNext Loop ' If a match is found, throw an error, if not, allow form validation to continue without issue If NoDup=0 Then 'Place error handling code here 'Session("CustomError") = Session("CustomError") & "Not a valid Email address (Duplicate).
" 'Response.Write "Error: E-Mail is a duplicate" %> <% Response.End Else End If End Function '************************************************************************************************************************************* %> <% 'Emelyn's Form Validation Sub Routines Sub GetFormItem(sItemName, sAliasName, iMinLength, iMaxLength, fRequired) varItem = TRIM(Request.Form(sItemName)) If sAliasName = "" Then sAliasName = sItemName If fRequired Then If varItem = "" Then Session("CustomError") = Session("CustomError") _ & "Please enter at least "&iMinLength&" characters in the """ _ & sAliasName & """ field.
" Else If Len(varItem) < iMinLength Then Session("CustomError") = _ Session("CustomError") & "Please enter at least " _ & iMinLength &" characters in the """ _ & sAliasName & """ field.
" If Len(varItem) > iMaxLength Then Session("CustomError") = _ Session("CustomError") & "Please enter at most " _ & iMaxLength &" characters in the """ _ & sAliasName & """ field.
" End If Else varItem = TRIM(Request.Form(sItemName)) End If Session(sItemName) = varItem End Sub Sub ServerSidePasswordValidation _ (sPassword1, sPassword2, iMin, iMax,bRequired) Call GetFormItem(sPassword1, "Password", iMin, iMax, bRequired) Call GetFormItem(sPassword2, "Verify Password", iMin, iMax, bRequired) bValidPassword = ( session(sPassword1) = session(sPassword2) ) if Not bValidPassword Then Session("CustomError") = _ Session("CustomError") _ & " Both Password fields must have the same value!
" End Sub Sub ServerSideEmailValidation _ (sItemName, sAliasName, iMinLength, iMaxLength, bRequired) Call GetFormItem (sItemName, sAliasName, iMinLength, iMaxLength, bRequired) If (InStr(session(sItemName),"@") < 2) Then Session("CustomError") = Session("CustomError") _ & "Not a valid Email address (missing '@')
" Else If ( InStr(InStr(session(sItemName),"@"),session(sItemName),".") < _ InStr(session(sItemName),"@")+2 ) Then Session("CustomError") = _ Session("CustomError") _ & "Not a valid Email address (missing '.')
" End If End Sub %>