<AcceptVerbs(HttpVerbs.Post)> _
Function Create(ByVal person As Person) As ActionResult
If person.Name.Trim().Length = 0 Then
ModelState.AddModelError("Name", "Name is required.")
End If
If ((person.Age < 1) Or (person.Age > 200)) Then
ModelState.AddModelError("Age", "Age must be within range 1 to 200.")
End If
If ((person.Zipcode.Trim().Length > 0) And Not (Regex.IsMatch(person.Zipcode, "^\d{5}$|^\d{5}-\d{4}$"))) Then
ModelState.AddModelError("Zipcode", "Zipcode is invalid.")
End If
If Not (Regex.IsMatch(person.Phone, "((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}")) Then
ModelState.AddModelError("Phone", "Phone number is invalid.")
End If
If Not (Regex.IsMatch(person.Email, "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")) Then
ModelState.AddModelError("Email", "Email format is invalid.")
End If
If Not ModelState.IsValid Then
Return View("Create", person)
End If
people.Add(person)
Return RedirectToAction("Index")
End Function