السلام عليكم ورحمة الله تعالى وبركاته
وجدت الكود التالي في أحد المشاريع الخاصة بال Regular Expression ولكني لم أفهم العديد من أجزائه
Imports System.Text.RegularExpressions
Public Class MatchingCharacters
Inherits System.Windows.Forms.Form
Const OnlyOneLetterRX As String = "a"
Const LetterAandAnyRX As String = "a.b"
Const NumbersWithPeriodRX As String = "15\.00"
'Validate Letter a Or More
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Public Function ValidateLetterA(ByVal TheString As String) As Boolean
Try
Dim rx As New Regex(OnlyOneLetterRX)
Return rx.IsMatch(TheString)
Catch ex As FormatException
Throw ex
Catch ex As Exception
Throw ex
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.ValidateLetterA(Me.TextBox1.Text) = True Then
MsgBox("Correct")
Else
MsgBox("No...(*&*)Only Letter a is Valid to be entered ... ")
End If
End Sub
'Validate A and One Or More Characters
Public Function ValidateLetterAandAny(ByVal TheString As String) As Boolean
Try
Dim rx As New Regex(LetterAandAnyRX)
Return rx.IsMatch(TheString)
Catch ex As FormatException
Throw ex
Catch ex As Exception
Throw ex
End Try
End Function
Private Sub btnLetterAandAny_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLetterAandAny.Click
If Me.ValidateLetterAandAny(Me.txtLetterAandAny.Text) = True Then
MsgBox("Correct--You Enter letter a And One More Character isn't it ?")
Else
MsgBox("No..(*&*)Only 2 letters should be Eneterd Started with Letter a ... ")
End If
End Sub
'Validate A and One Or More Characters
Public Function ValidateNumbersWithPeriod(ByVal TheString As String) As Boolean
Try
Dim rx As New Regex(NumbersWithPeriodRX)
Return rx.IsMatch(TheString)
Catch ex As FormatException
Throw ex
Catch ex As Exception
Throw ex
End Try
End Function
Private Sub btnNumbersWithPeriod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumbersWithPeriod.Click
If Me.ValidateNumbersWithPeriod(Me.txtNumbersWithPeriod.Text) = True Then
MsgBox("Correct--Your Number is 15.00 or More ")
Else
MsgBox("No..(*&*)Incorrect Value ... ")
End If
End Sub
Private Sub MatchingCharacters_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Classأسئلتي :
1.مادور العبارة التالية ؟
Imports System.Text.RegularExpressions
2.ما معنى الأجزاء التالية ودور كل كلمة فيها ؟
Public Function ValidateLetterA(ByVal TheString As String) As Boolean
Try
Dim rx As New Regex(OnlyOneLetterRX)
Return rx.IsMatch(TheString)
Catch ex As FormatException
Throw ex
Catch ex As Exception
Throw ex
End Try
End FunctionMe.ValidateLetterA(Me.TextBox1.Text) = True
