String contains regex
string-contains-regex.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this section create string variables.
string stringColors = "Red Orange Maroon Coral DarkCyan";
string stringColorsWithSerial = "1.Red 2.Orange 3.Maroon 4.Coral 5.DarkCyan";
Label1.Text = "string..................<br />";
Label1.Text += "stringColors: " + stringColors;
Label1.Text += "<br />stringColorsWithSerial: " + stringColorsWithSerial;
//check string contains only letters and space character using regular expression
Regex rex = new Regex("^[a-zA-Z ]+$");
Boolean result = rex.IsMatch(stringColors);
Boolean result2 = rex.IsMatch(stringColorsWithSerial);
Label1.Text += "<br /><br />stringColors contains letters and space only? " + result.ToString();
Label1.Text += "<br /><br />stringColorsWithSerial contains letters and space only? " + result2.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string contains regex</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string contains regex
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="string contains regex"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to perform regex case insensitive string replace
- How to replace a character in a string from a starting index
- How to replace first occurrence of a substring within a string
- How to append a char to a string
- How to add backslash to a string
- How to concatenate multiple strings
- How to convert a delimited string to a dictionary
- How to convert a string to a double array
- How to convert a string to a guid
- How to convert a string to a generic list