SamarthSalunkhe
Board Regular
- Joined
- Jun 14, 2021
- Messages
- 103
- Office Version
- 2016
- Platform
- Windows
Hi All,
I am using the below code to restrict numbers only in the textbox of user form, it is working very well. just for knowledge purposes, I want to change restrictions like in the test box I want to allow the first 4 characters can be any alphabet (A-Z) and the fifth one should be zero ( 0 ) or any numeric value. Eg. : "ABCD0BD459"
I am using the below code to restrict numbers only in the textbox of user form, it is working very well. just for knowledge purposes, I want to change restrictions like in the test box I want to allow the first 4 characters can be any alphabet (A-Z) and the fifth one should be zero ( 0 ) or any numeric value. Eg. : "ABCD0BD459"
VBA Code:
Private Sub txtMobile_Change()
'Mobile number Must be in Numbers only.
Dim x As Long
Dim a As String
a = "##########"
With txtMobile
x = Len(.Text)
If Not .Text Like Left(a, x) Then
.Text = Left(.Text, x - 1): MsgBox "Mobile number Must be Numeric", vbExclamation, "Incorrect Mobile Number"
End If
End With
End Sub