30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

672 Strings, Characters and Regular Expressions Chapter 15<br />

57 txtLast.Focus()<br />

58<br />

59 Return<br />

60 End If<br />

61<br />

62 ' if first name format invalid show message<br />

63 If Not Regex.Match(txtFirst.Text, _<br />

64 "^[A-Z][a-zA-Z]*$").Success Then<br />

65<br />

66 ' first name was incorrect<br />

67 MessageBox.Show("Invalid First Name", "Message")<br />

68 txtFirst.Focus()<br />

69<br />

70 Return<br />

71 End If<br />

72<br />

73 ' if address format invalid show message<br />

74 If Not Regex.Match(txtAddress.Text, "^[0-9]+\s+([a-zA-Z]" & _<br />

75 "+|[a-zA-Z]+\s[a-zA-Z]+)$").Success Then<br />

76<br />

77 ' address was incorrect<br />

78 MessageBox.Show("Invalid Address", "Message")<br />

79 txtAddress.Focus()<br />

80<br />

81 Return<br />

82 End If<br />

83<br />

84 ' if city format invalid show message<br />

85 If Not Regex.Match(txtCity.Text, "^([a-zA-Z]+|[a-zA-Z]" & _<br />

86 "+\s[a-zA-Z]+)$").Success Then<br />

87<br />

88 ' city was incorrect<br />

89 MessageBox.Show("Invalid City", "Message")<br />

90 txtCity.Focus()<br />

91<br />

92 Return<br />

93 End If<br />

94<br />

95 ' if state format invalid show message<br />

96 If Not Regex.Match(txtState.Text, _<br />

97 "^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success Then<br />

98<br />

99 ' state was incorrect<br />

100 MessageBox.Show("Invalid State", "Message")<br />

101 txtState.Focus()<br />

102<br />

103 Return<br />

104 End If<br />

105<br />

106 ' if zip code format invalid show message<br />

107 If Not Regex.Match(txtZip.Text, "^\d{5}$").Success Then<br />

108<br />

Fig. 15.22 Validating user information using regular expressions (part 3 of 5).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!