This example is somewhat simpler to understand because it does not use the complex object structure used by the drop-down list box. The previous example, however, checks the actual contents of the list and does not rely on the position of the item in the list. In other cases, you may not have a choice but to use the previous method.
At this point, try the form and make sure that it does not let you select “Select Your Version” or the series of dashes. You now have basic validation for your data entry form. The next section deals with specialized validation for e-mail addresses.
Validating E-Mail Addresses
One of the most common fields on Internet data entry forms is a field for a user’s e-mail address. Many users, however, do not know how to format their e-mail address correctly, and you end up getting bad, unusable e-mail addresses. This section shows you some ways to validate e-mail address formats so that the user can learn how his e-mail address should be written on the Internet.
No matter what your e-mail address is, it follows the following format:
user@host.domain
• user. This is your user ID. It may be a simple word, such as easmith. CompuServe addresses use two numbers separated by a period, and many systems use first and last name, such as Eric.Smith, as the user ID.
• host. This is typically the name of your Internet domain, such as inquiry or northcomp. The host parameter must be at least one word; however, it can have multiple words separated by spaces, as in mailhost.inquiry.com or www.mcp.com.
• domain. This final portion of your e-mail address indicates the type of system you are on. Typical domains include .edu (educational institution), .com (commercial sites), .gov (government sites), and .org (non-profit organizations). If you have an e-mail address outside the United States, the last part of your e-mail address will be a two-letter abbreviation that indicates the country in which your domain is located. Following is a list of all the current country codes and domains used on the Internet:
AD Andorra
AE United Arab Emirates
AF Afghanistan
AG Antigua and Barbuda
AI Anguilla
AL Albania
AM Armenia
AN Netherlands Antilles
AO Angola
AQ Antarctica
AR Argentina
AS American Samoa
AT Austria
AU Australia
AW Aruba
AZ Azerbaijan
BA Bosnia and Herzegovina
BB Barbados
BD Bangladesh
BE Belgium
BF Burkina Faso
BG Bulgaria
BH Bahrain
BI Burundi
BJ Benin
BM Bermuda
BN Brunei Darussalam
BO Bolivia
BR Brazil
BS Bahamas
BT Bhutan
BV Bouvet Island
BW Botswana
BY Belarus
BZ Belize
CA Canada
CC Cocos (Keeling) Islands
CF Central African Republic
CG Congo
CH Switzerland
CI Cote D’Ivoire (Ivory Coast)
CK Cook Islands
CL Chile
CM Cameroon
CN China
CO Colombia
CR Costa Rica
CS Czechoslovakia (former)
CU Cuba
CV Cape Verde
CX Christmas Island
CY Cyprus
CZ Czech Republic
DE Germany
DJ Djibouti
DK Denmark
DM Dominica
DO Dominican Republic
DZ Algeria
EC Ecuador
EE Estonia
EG Egypt
EH Western Sahara
ER Eritrea
ES Spain
ET Ethiopia
FI Finland
FJ Fiji
FK Falkland Islands (Malvinas)
FM Micronesia
FO Faroe Islands
FR France
FX France, Metropolitan
GA Gabon
GB Great Britain (UK)
GD Grenada
GE Georgia
GF French Guiana
GH Ghana
GI Gibraltar
GL Greenland
GM Gambia
GN Guinea
GP Guadeloupe
GQ Equatorial Guinea
GR Greece
GS S. Georgia and S. Sandwich Isls.
GT Guatemala
GU Guam
GW Guinea-Bissau
GY Guyana
HK Hong Kong
HM Heard and McDonald Islands
HN Honduras
HR Croatia (Hrvatska)
HT Haiti
HU Hungary
ID Indonesia
IE Ireland
IL Israel
IN India
IO British Indian Ocean Territory
IQ Iraq
IR Iran
IS Iceland
IT Italy
JM Jamaica
JO Jordan
JP Japan
KE Kenya
KG Kyrgyzstan
KH Cambodia
KI Kiribati
KM Comoros
KN Saint Kitts and Nevis
KP Korea (North)
KR Korea (South)
KW Kuwait
KY Cayman Islands
KZ Kazakhstan
LA Laos
LB Lebanon
LC Saint Lucia
LI Liechtenstein
LK Sri Lanka
LR Liberia
LS Lesotho
LT Lithuania
LU Luxembourg
LV Latvia
LY Libya
MA Morocco
MC Monaco
MD Moldova
MG Madagascar
MH Marshall Islands
MK Macedonia
ML Mali
MM Myanmar
MN Mongolia
MO Macau
MP Northern Mariana Islands
MQ Martinique
MR Mauritania
MS Montserrat
MT Malta
MU Mauritius
MV Maldives
MW Malawi
MX Mexico
MY Malaysia
MZ Mozambique
NA Namibia
NC New Caledonia
NE Niger
NF Norfolk Island
NG Nigeria
NI Nicaragua
NL Netherlands
NO Norway
NP Nepal
NR Nauru
NT Neutral Zone
NU Niue
NZ New Zealand (Aotearoa)
OM Oman
PA Panama
PE Peru
PF French Polynesia
PG Papua New Guinea
PH Philippines
PK Pakistan
PL Poland
PM St. Pierre and Miquelon
PN Pitcairn
PR Puerto Rico
PT Portugal
PW Palau
PY Paraguay
QA Qatar
RE Reunion
RO Romania
RU Russian Federation
RW Rwanda
SA Saudi Arabia
SB Solomon Islands
SC Seychelles
SD Sudan
SE Sweden
SG Singapore
SH St. Helena
SI Slovenia
SJ Svalbard and Jan Mayen Islands
SK Slovak Republic
SL Sierra Leone
SM San Marino
SN Senegal
SO Somalia
SR Suriname
ST Sao Tome and Principe
SU U.S.S.R (former)
SV El Salvador
SY Syria
SZ Swaziland
TC Turks and Caicos Islands
TD Chad
TF French Southern Territories
TG Togo
TH Thailand
TJ Tajikistan
TK Tokelau
TM Turkmenistan
TN Tunisia
TO Tonga
TP East Timor
TR Turkey
TT Trinidad and Tobago
TV Tuvalu
TW Taiwan
TZ Tanzania
UA Ukraine
UG Uganda
UK United Kingdom
UM U.S. Minor Outlying Islands
US United States
UY Uruguay
UZ Uzbekistan
VA Vatican City State (Holy See)
VC Saint Vincent and the Grenadines
VE Venezuela
VG Virgin Islands (British)
VI Virgin Islands (U.S.)
VN Vietnam
VU Vanuatu
WF Wallis and Futuna Islands
WS Samoa
YE Yemen
YT Mayotte
YU Yugoslavia
ZA South Africa
ZM Zambia
ZR Zaire
ZW Zimbabwe
COM U.S. Commercial
EDU U.S. Educational
GOV U.S. Government
INT International
MIL U.S. Military
NET Network
ORG Non-Profit Organization
ARPA Old-Style Arpanet
NATO Nato Field
This list helps you to determine where your visitors are from. Now that you understand how e-mail addresses should be formatted, you can write code to validate these formats and to catch common mistakes.
Based on the standard format for e-mail addresses, a few assumptions can be made about any e-mail address that is entered in your form:
• Must be non-zero length
• Must have one and only one @ character
• Must contain at least one period character
• May not contain any spaces
The first part of the validation code checks the last three conditions by using common string manipulation functions. You have already checked the length of the e-mail address, so you do not need to repeat that task.
Checking for a Single @ Character
The quickest way to verify that only one @ character was used in an e-mail address is to write a loop that reads the entire string and looks for the @ character. The code that performs this task follows:
Dim i
Dim iAtCount
iAtCount = 0
sTemp = frmDataEntry.parm_sender_email.Value
For i = 1 To Len(sTemp)
If Mid(sTemp, i, 1) = "@" Then
iAtCount = iAtCount + 1
If iAtCount > 1 Then
Alert "Your e-mail address can only contain one @ character."
frmDataEntry.parm_sender_email.focus
Exit Sub
End If
End If
Next ' Next i
if iAtCount <> 1 Then
Alert "Your e-mail address must contain an @ character."
frmDataEntry.parm_sender_email.focus
Exit Sub
End If
The For loop starts at the beginning of the e-mail address and watches for @ characters. If it gets more than one, it stops immediately and generates an error message. If the loop gets to the end of the e-mail address and no @ character was found, a different error message is shown to the user.
Checking for a Period Character
This task is essentially the same as checking for the @ character, except for the fact that finding more than one period is not necessarily an error. To add the code for this validation, change the loop that you created to check for @ characters. The code from the previous validation with a few minor changes is as follows:
Dim i
Dim iAtCount
Dim iPeriods
iAtCount = 0
iPeriods = 0
sTemp = frmDataEntry.parm_sender_email.Value
For i = 1 To Len(sTemp)
If Mid(sTemp, i, 1) = "@" Then
iAtCount = iAtCount + 1
If iAtCount > 1 Then
Alert "Your e-mail address can only contain one @ character."
frmDataEntry.parm_sender_email.focus
Exit Sub
End If
ElseIf Mid(sTemp, i, 1) = "." Then
iPeriods = iPeriods + 1
End If
Next ' Next i
if iAtCount <> 1 Then
Alert "Your e-mail address must contain an @ character."
frmDataEntry.parm_sender_email.focus
Exit Sub
End If
If iPeriods < 1 Then
Alert "Your e-mail address must contain at least one period."
FrmDataEntry.parm_sender_email.focus
Exit Sub
End If
Adding the two lines of code within the For loop that was already there saves time by checking for both error conditions in the same loop. The code to check for periods is nearly identical to the code that checks for the @ character. If the character is a period, the iPeriods counter increases by one. If, when the loop is done, the iPeriods counter is less than one, an error message is shown to the user.
Checking for Spaces
This final basic check of a user’s e-mail address ensures that no spaces are embedded within the address. Because this code is even simpler than the previous two validations, there is no need for a lengthy explanation. Using the previous block of code, make the following changes:
Dim i
Dim iAtCount
Dim iPeriods
iAtCount = 0
iPeriods = 0
sTemp = frmDataEntry.parm_sender_email.Value
For i = 1 To Len(sTemp)
If Mid(sTemp, i, 1) = "@" Then
iAtCount = iAtCount + 1
If iAtCount > 1 Then
Alert "Your e-mail address can only contain one @ character."
frmDataEntry.parm_sender_email.focus
Exit Sub
End If
ElseIf Mid(sTemp, i, 1) = "." Then
iPeriods = iPeriods + 1
ElseIf Mid(sTemp, I, 1) = " " Then
Alert "Your e-mail address may not contain any spaces."
frmDataEntry.parm_sender_email.focus
Exit Sub
End If
Next ' Next i
if iAtCount <> 1 Then
Alert "Your e-mail address must contain an @ character."
frmDataEntry.parm_sender_email.focus
Exit Sub
End If
If iPeriods < 1 Then
Alert "Your e-mail address must contain at least one period."
FrmDataEntry.parm_sender_email.focus
Exit Sub
End If
After you add the three previous code blocks to your script, you are protected against the most common errors encountered in entering e-mail addresses: spaces, extra @s, and zero period characters.
posted by gonsa VP at 11:08 AM
ESTE
es el primer post
911 G
posted by gonsa VP at 10:48 AM