0

I am working on a C#.NET web application that use JQuery mobile for its view.

in a view I have a form that contains the following input field in which the user can put an URL:

<label for="nome">URL*:</label>
<input type="text" data-clear-btn="true" name="oval.url" id="url" data-mini="true" data-inline="true"  required="required"  value="@Model.oval.URL" />

My problem is that, using the previous code snippet, the user can insert any string but I want that it is considered as a valid value only a real URL (something like www.thisisanurl.com and not something this is not an url)

Can I do this check using JQuery? Or what can I do to solve this issue?

Tnx

AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

2 Answers2

0

Try adding this validation:

var urlregex =new RegExp("^(http:\/\/www.|https:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
if (urlregex.test(textval)){
    ...
}

This could be useful.

Genzotto
  • 1,954
  • 6
  • 26
  • 45
0

Since it is jquery mobile I'll assume it is being viewed on a mobile device. Most mobile browsers support HTML5 input types. http://www.w3.org/TR/html-markup/input.url.html

<input type="url" ... />

Jack
  • 8,851
  • 3
  • 21
  • 26