I´m really stuck at a validation that I need to do. If anyone could help me I would appreciate.
I have a form where I put a text field to the user insert a page addreess. I inserted two validations. One for when the field is empty and the other to check if the link already exists in the database. So far, so good. The problem is...
When the user insert a the page address I can´t have the "http://" recorded in my db. So I have to validade the field in order to never have it recorded.
One other option that I was thinkings is to accept it in the form but don´t record in the db, disconsidering this part from the address.
mclazarini
Member
63 Points
57 Posts
Validation
Apr 24, 2012 02:59 AM|LINK
Hi one more time!
I´m really stuck at a validation that I need to do. If anyone could help me I would appreciate.
I have a form where I put a text field to the user insert a page addreess. I inserted two validations. One for when the field is empty and the other to check if the link already exists in the database. So far, so good. The problem is...
When the user insert a the page address I can´t have the "http://" recorded in my db. So I have to validade the field in order to never have it recorded.
One other option that I was thinkings is to accept it in the form but don´t record in the db, disconsidering this part from the address.
thanks a lot!
Thanks a lot.
Mikesdotnett...
All-Star
154941 Points
19870 Posts
Moderator
MVP
Re: Validation
Apr 24, 2012 04:49 AM|LINK
What's the problem?
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
mclazarini
Member
63 Points
57 Posts
Re: Validation
Apr 25, 2012 02:39 AM|LINK
Actually I don´t know how to make this validation.
I can´t have the "http" recorded in my database but I don´t know how to write de code to prevent the user from posting it.
if (link = ( contains "http")) {
linkErrorMessage = "You must specify an email address.";
isValid = false; }
Thanks a lot
Mikesdotnett...
All-Star
154941 Points
19870 Posts
Moderator
MVP
Re: Validation
Apr 25, 2012 04:50 AM|LINK
Almost:
var link = Request["link"]; if(link.Contains("http")){ //failedAlthough you might be better off with:
if(link.StartsWith("http")){ //failedOr you might even accept it and then take care of stripping the http off:
var link = ""; if(IsPost && !Request["link"].IsEmpty()){ link = Request["link"].Replace("http://", ""); }Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
mclazarini
Member
63 Points
57 Posts
Re: Validation
Apr 25, 2012 10:25 PM|LINK
Thanks a lot Mike. That is exactly what I was looking for.
Mclazarini