Wednesday, 7 August 2013

Regular expression to check url and shared file path

Regular expression to check url and shared file path

Im using below regular expression for Dataform field for checking whether
the entered text starts with http:// or https:// or \
Im using System.componentmodel.DataAnnotations.RegularExpressionAttribute
[Display(Name = "URL", Description = "URL")]
[RegularExpression(@"^(http[s]{0,1}://|\\)", ErrorMessage = "Please enter
valid Url or filepath")] public string URL { get; set; }
but in dataform field it is throwing error if any text is enetered after
http:// or https:// or \ ie
**http://google.com** ---failed
**https://aa** --failed
**\\a** ----failed
I just want to pass all the above scenarios ...on high level the regular
expression should just only check whether entered text starts with http://
or https:// or \
And even dataform is throwing error for the field when user enters and
delete the text and click on tab.the error is URL is required field ,but I
didn't mention required attribute for this property. Please help

No comments:

Post a Comment