I want to validate a string value from textbox.
Validation requirements are:
- Exactly 2 characters
- Hex characters only
How can I do this?
I want to validate a string value from textbox.
Validation requirements are:
How can I do this?
Use a Regex validator control with the expression: ^[0-9A-F]{2}$
String^ temp = "012345679abcdefABCDEF";
if (temp->IndexOf(e->KeyChar) == -1)
{
e->Handled = true;
}
use this for hex character control
//Use this method and before calling it ..pass or parse out the string.Substring(0,2)
public string ConvertToHex(string asciiString)
{
var newasciiString = Substring(asciiString,0,2);
string hex = "";
foreach (char c in newasciiString)
{
int tmp = c;
hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));
}
return hex;
}