Need some regular expressions help.
So far I have my code working to allow a limited number of special characters. However, I don’t know how to get it to only allow them in the middle and never the end.
Can someone help me figure that part out?
Here is the code I am using in c#:
Regex uRLToVal= new Regex("^[A-Za-z0-9-_.+!*]*$");
if (!uRLToVal.IsMatch(this.mainURL))
{
results.AddPropertyError("Your Entry can only contain letters, numbers, underscores, periods, plus, exclamation marks and hypens. Special characters should always be inside numbers or letters. Example: v!v is OK BUT NOT !vv or vv!");
}
which means :
match must begin with at least one numeric or alpha char:
[A-Z-z0-9]+That sequence may be followed by zero or many special chars
-_.+!*followed by at least one numeric or alpha char.This second combination can happen zero or many times (example :
asdf-e*r!asdf, oraare valid)