2

I found a Jquery plugin from JQueryValidation.

I'm validating URLs which is entered in the Textbox on submit. Its working perfectly when i enter the hosted URL's. Https and http Like https://www.google.co.in and http://test.com/

Demo : Here

The problem is when i enter asp.net mvc local host urls its not allowing as a valid urls. Like http://localhost:65350/Test.htm

How do I allow local host urls also throgh jquery.validate.min.js?

Is there any custom methods can be added for Hosted urls and localhost urls? which will be validated at same time for a field.

7
  • 1
    may be this help you jsfiddle.net/4Nv2d/1 Commented Jul 7, 2014 at 11:43
  • weblogs.asp.net/owscott/introducing-testing-domain-localtest-me Commented Jul 7, 2014 at 13:48
  • 1
    yes, localtest.me, not localhost.me Commented Jul 7, 2014 at 13:57
  • 1
    You simply need to create a new rule/method using the addMethod method. Use the function from the plugin's URL method as your base code and modify it to suit your needs. So are you asking how to create a rule with addMethod() or are you asking how to write the custom URL regex that includes localhost? Commented Jul 7, 2014 at 16:42
  • Thank you all for the response. I asking how to write the custom URL regex that includes localhost. Commented Jul 8, 2014 at 4:49

1 Answer 1

1

There's an additional method in jQuery Validation called url2 that allows a url without a dot, thus allowing localhost url's.

Use the rules method to add it like so:

$( "#email_input" ).rules( "add", {
  url2: true
});

You can check out the source here: https://github.com/jzaefferer/jquery-validation/blob/master/src/additional/url2.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.