06-01-24, 02:43 AM
كود لمنع كتابة الحروف في TextBox
كتابة حرف وبعدها ثلاثة ارقام مع رسالة تنبيه
كتابة "رقم رقم رقم" وتضيف فراغ بين كل رقمين
PHP كود :
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) Then
e.Handled = True ' منع الحرف من الظهور في الـ TextBox
End If
End Sub
كتابة حرف وبعدها ثلاثة ارقام مع رسالة تنبيه
PHP كود :
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
' يسمح بالأحرف فقط في البداية
If TextBox1.Text.Length = 0 AndAlso Not Char.IsLetter(e.KeyChar) Then
e.Handled = True ' منع الإدخال إذا لم يكن حرفًا في البداية
End If
' بعد الحرف، يسمح بالأرقام الثلاثة فقط
If TextBox1.Text.Length > 0 AndAlso Not Char.IsDigit(e.KeyChar) Then
e.Handled = True ' منع الإدخال إذا لم يكن رقمًا بعد الحرف
End If
' عند وصول عدد الأحرف لثلاثة، يمنع المزيد من الإدخال
If TextBox1.Text.Length = 4 Then
e.Handled = True ' منع المزيد من الأرقام بعد ثلاثة
MessageBox.Show("الرجاء إدخال حرف وثلاثة أرقام فقط!", "تنبيه")
End If
End Sub
كتابة "رقم رقم رقم" وتضيف فراغ بين كل رقمين
PHP كود :
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
' التأكد من أن الحرف المدخل هو رقم وليس فراغ
If Char.IsDigit(e.KeyChar) Then
' التأكد من عدم تجاوز حد الأرقام المسموح بها
If TextBox1.TextLength < 9 Then ' يمكنك تغيير الرقم 9 حسب الحالة
' لا يتم إضافة فراغ بين الأرقام عند الإدخال
If TextBox1.TextLength > 0 AndAlso TextBox1.TextLength Mod 3 = 2 Then
TextBox1.Text += " " & e.KeyChar
TextBox1.SelectionStart = TextBox1.TextLength
e.Handled = True
ElseIf TextBox1.TextLength = 0 OrElse TextBox1.TextLength Mod 3 <> 2 Then
TextBox1.Text += e.KeyChar
TextBox1.SelectionStart = TextBox1.TextLength
e.Handled = True
End If
Else
e.Handled = True ' منع المزيد من الإدخال بعد الحد المسموح به
MessageBox.Show("الرجاء إدخال أقل من 9 أرقام!", "تنبيه")
End If
ElseIf Not Char.IsControl(e.KeyChar) Then
e.Handled = True ' منع أي شيء غير الأرقام
End If
End Sub
