How to validate a multi line Address text box using regex

  • Thread starter Thread starter Sushil Agarwal
  • Start date Start date
S

Sushil Agarwal

Guest
Hi experts,

can u please help me to get regex to validate a multi line address text box

to allow case incentive alphabets, numbers and only # / , - &

i tried @"^(\w*\s*[\#\-\,\/\(\)\&]*)+"

but it test address

Plot No 6, @Sector:10, Iie Sidcul, Pantnagar, Uttaranchal-263153

it passes the criteria it , @ before sector and : before 10 should not be allowe

Regex regex = new Regex(@"^(\w*\s*[\#\-\,\/\(\)\&]*)+", RegexOptions.Multiline);
Match match = regex.Match(txtaddress.Text);
if (match.Success)
{
e.Cancel = false;
errorProvider1.Clear();
}
else
{
e.Cancel = true;
errorProvider1.SetError(txtaddress, "Special Characters except (#/,-&) not allowed");
}
will to be possible to show offending character and their position in a message-box

Continue reading...
 
Back
Top