0% found this document useful (0 votes)
55 views3 pages

Text Only: Imports

The document contains code snippets for validating text, number, email and phone number inputs in text boxes. It includes regular expressions to check for valid characters in text and number fields, a valid email format, and 10 digit phone numbers. It also shows code for removing special characters from a string and for defaulting empty text boxes to "--".

Uploaded by

Suguna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views3 pages

Text Only: Imports

The document contains code snippets for validating text, number, email and phone number inputs in text boxes. It includes regular expressions to check for valid characters in text and number fields, a valid email format, and 10 digit phone numbers. It also shows code for removing special characters from a string and for defaulting empty text boxes to "--".

Uploaded by

Suguna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Text only

Imports System.Text.RegularExpressions

If Asc(e.KeyChar) <> 8 Then


If Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then
e.Handled = True
End If
End If

Number only

If Asc(e.KeyChar) <> 8 Then


If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If

Email validation

Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-


zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
Dim emailAddressMatch As Match = Regex.Match(emailaddress, pattern)
If emailAddressMatch.Success Then
emailaddresscheck = True
Else
emailaddresscheck = False
End If

Phone validatin
Dim phonenumber As New Regex("\d{10}")
If phonenumber.IsMatch(TextBox4.Text) Then

Else
MsgBox("Not Valid phone number!")
TextBox4.Text = ""

End If
Avoid special character

public static string RemoveSpecialCharacters(string str)


{
// Strips all special characters and spaces from a string.
return Regex.Replace(str, "[^a-zA-Z0-9_.]+", "",
RegexOptions.Compiled);
}

protected void Button1_Click(object sender, EventArgs e)


{
string str=TextBox1.Text;
TextBox2.Text=RemoveSpecialCharacters(str);
}

ElseIf TextBox3.Text = "" Then


TextBox3.Text = "--"
ElseIf TextBox4.Text = "" Then
TextBox4.Text = "--"
ElseIf TextBox5.Text = "" Then
TextBox5.Text = "--"
ElseIf TextBox6.Text = "" Then
TextBox6.Text = "--"
ElseIf TextBox7.Text = "" Then
TextBox7.Text = "--"
ElseIf TextBox8.Text = "" Then
TextBox8.Text = "--"
ElseIf TextBox9.Text = "" Then
TextBox9.Text = "--"
ElseIf TextBox10.Text = "" Then
TextBox10.Text = "--"
ElseIf TextBox11.Text = "" Then
TextBox11.Text = "--"
ElseIf TextBox12.Text = "" Then
TextBox12.Text = "--"
ElseIf TextBox13.Text = "" Then
TextBox13.Text = "--"
ElseIf TextBox14.Text = "" Then
TextBox14.Text = "--"
ElseIf TextBox15.Text = "" Then
TextBox15.Text = "--"
ElseIf TextBox16.Text = "" Then
TextBox16.Text = "--"
ElseIf TextBox17.Text = "" Then
TextBox17.Text = "--"
ElseIf TextBox18.Text = "" Then
TextBox18.Text = "--"
ElseIf TextBox19.Text = "" Then
TextBox19.Text = "--"
ElseIf TextBox20.Text = "" Then
TextBox20.Text = "--"
ElseIf TextBox21.Text = "" Then
TextBox21.Text = "--"
ElseIf TextBox22.Text = "" Then
TextBox22.Text = "--"
ElseIf TextBox23.Text = "" Then
TextBox23.Text = "--"
ElseIf TextBox24.Text = "" Then
TextBox24.Text = "--"
ElseIf TextBox25.Text = "" Then
TextBox25.Text = "--"
ElseIf TextBox26.Text = "" Then
TextBox26.Text = "--"

You might also like