📄 validation.vb
字号:
' Human Resources Management System (HRMS)
'
' Programmed by: Nura Tijjani Abubakar (ntagrafix@yahoo.com)
' Submitted to: Mr. Ravindran Kanapathy
'
' Oxford Brookes University (OBU)
' Final Year Project (November, 2007)
Imports System.Text.RegularExpressions
Public Class Validation
Public Function ValidateString(ByVal Field2Validate As String) As Boolean
If Field2Validate <> "" Then
Dim reg As New Regex("^([a-zA-Z0-9]+[.,]?[ ]?)+$")
If Not (reg.IsMatch(Field2Validate.Trim())) Then
Return False
Else
Return True
End If
End If
End Function
Public Function ValidatePhone(ByVal Field2Validate) As Boolean
If Field2Validate <> "" Then
Dim reg As New Regex("(^\d{0,5}[- ]?\d{0,6}[- ]?\d{5,10}$)")
If Not (reg.IsMatch(Field2Validate.Trim())) Then
Return False
Else
Return True
End If
End If
End Function
Public Function ValidatePincode(ByVal Field2Validate) As Boolean
If Field2Validate <> "" Then
Dim reg As New Regex("^\d{1,6}$")
If Not (reg.IsMatch(Field2Validate.Trim())) Then
Return False
Else
Return True
End If
End If
End Function
Public Function ValidateMobile(ByVal Field2Validate) As Boolean
If Field2Validate <> "" Then
Dim reg As New Regex("^\d{5,10}$")
If Not (reg.IsMatch(Field2Validate.Trim())) Then
Return False
Else
Return True
End If
End If
End Function
Public Function ValidateEmail(ByVal Field2Validate) As Boolean
If Field2Validate <> "" Then
Dim reg As New Regex("^([0-9a-zA-Z]+[-._])*[0-9a-zA-Z]+@([0-9a-zA-Z]+[.])+[a-zA-Z]{2,3}$")
If Not (reg.IsMatch(Field2Validate.Trim())) Then
Return False
Else
Return True
End If
End If
End Function
Public Function ValidateMsYs(ByVal Field2Validate) As Boolean
If Field2Validate <> "" Then
Dim reg As New Regex("^\d{1,2}$")
If Not (reg.IsMatch(Field2Validate.Trim())) Then
Return False
Else
Return True
End If
End If
End Function
Public Function Field(ByVal oDetails As Object, Optional ByVal tablename As String = "Cand") As Boolean
Dim VStatus As Boolean = True
Dim ErrMessage As String
Select Case tablename
Case "Agent"
If oDetails.AgName = "" Then
ErrMessage += "- Agent Name Field Cannot be Null " & vbNewLine & ""
VStatus = False
Else
If Not ValidateString(oDetails.AgName) Then
ErrMessage += "- Invalid Input in Name " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.AgContact <> "" Then
If Not ValidateString(oDetails.AgContact) Then
ErrMessage += "- Invalid Input in Contact Name " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.AgCity <> "" Then
If Not ValidateString(oDetails.AgCity) Then
ErrMessage += "- Invalid Input in City " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.AgPincode <> "" Then
If Not ValidatePincode(oDetails.AgPincode) Then
ErrMessage += "- Invalid Input in Pincode " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.AgPhone <> "" Then
If Not ValidatePhone(oDetails.AgPhone) Then
ErrMessage += "- Invalid Input in Phone " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.AgMobile <> "" Then
If Not ValidateMobile(oDetails.AgMobile) Then
ErrMessage += "- Invalid Input in Mobile Number " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.AgFax <> "" Then
If Not ValidatePhone(oDetails.AgFax) Then
ErrMessage += "- Invalid Input in Fax Number " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.AgEmail <> "" Then
If Not ValidateEmail(oDetails.AgEmail) Then
ErrMessage += "- Invalid Input in Email Address " & vbNewLine & ""
VStatus = False
End If
End If
Case "Cand"
'Applied Date
If oDetails.AppliedOn > Date.Now.ToShortDateString Then
ErrMessage += "- Applied On Date Cannot be Feature Date " & vbNewLine & ""
VStatus = False
End If
'Name
If oDetails.Name = "" Then
ErrMessage += "- Name Field Cannot be Null " & vbNewLine & ""
VStatus = False
Else
If Not ValidateString(oDetails.Name) Then
ErrMessage += "- Invalid Input in Name " & vbNewLine & ""
VStatus = False
End If
End If
'Father Name
If oDetails.FName <> "" Then
If Not ValidateString(oDetails.FName) Then
ErrMessage += "- Invalid Input in Father Name " & vbNewLine & ""
VStatus = False
End If
End If
'Date of Birth
Dim Cand_DoB, Cur_Date As Date
Dim Age As Integer
Cand_DoB = CDate(oDetails.DoB).ToShortDateString
Cur_Date = Date.Now.ToShortDateString
Age = DateDiff(DateInterval.Month, Cand_DoB, Cur_Date)
Age = Int(Age / 12)
If (Age < 18) Or (Age > 55) Then
ErrMessage += "- Age Limit is between 18 to 55 " & vbNewLine & ""
VStatus = False
End If
'Place of Birth
If oDetails.PoB <> "" Then
If Not ValidateString(oDetails.PoB) Then
ErrMessage += "- Invalid Input in Place of Birth " & vbNewLine & ""
VStatus = False
End If
End If
'City
If oDetails.City <> "" Then
If Not ValidateString(oDetails.City) Then
ErrMessage += "- Invalid Input in City " & vbNewLine & ""
VStatus = False
End If
End If
'Pincode
If oDetails.Pincode <> "" Then
If Not ValidatePincode(oDetails.Pincode) Then
ErrMessage += "- Invalid Input in Pincode " & vbNewLine & ""
VStatus = False
End If
End If
'Phone
If oDetails.Phone <> "" Then
If Not ValidatePhone(oDetails.Phone) Then
ErrMessage += "- Invalid Input in Phone Number " & vbNewLine & ""
VStatus = False
End If
End If
'Mobile
If oDetails.Mobile <> "" Then
If Not ValidateMobile(oDetails.Mobile) Then
ErrMessage += "- Invalid Input in Mobile Number " & vbNewLine & ""
VStatus = False
End If
End If
'Email
If oDetails.Email <> "" Then
If Not ValidateEmail(oDetails.Email) Then
ErrMessage += "- Invalid Input in Email Address " & vbNewLine & ""
VStatus = False
End If
End If
'Passport Details - [START]
If oDetails.PPNo <> "" Then
Dim PP As New Regex("^([a-zA-Z]{1}\s{0,1}\d{6,8}$)")
If Not (PP.IsMatch(oDetails.PPNo.Trim())) Then
ErrMessage += "- Invalid Input in Passport Number " & vbNewLine & ""
VStatus = False
End If
If oDetails.PoI <> "" Then
If Not ValidateString(oDetails.PoI) Then
ErrMessage += "- Invalid Input in Passport Details Place of Issue " & vbNewLine & ""
VStatus = False
End If
End If
If oDetails.DoI > Date.Now.ToShortDateString Then
ErrMessage += "- Passport's Date of Issue Cannot be Feature Date " & vbNewLine & ""
VStatus = False
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -