Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6971283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:49:12+00:00 2026-05-27T16:49:12+00:00

Hello i wrote a regular expression to validate URL jQuery.validator.addMethod(url_validation, function (value, element) {

  • 0

Hello i wrote a regular expression to validate URL

jQuery.validator.addMethod("url_validation", function (value, element) {
    return this.optional(element) || /^([ \t+])?(([http|https|HTTPS|HTTP]+:\/\/))?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/i.test(value);
}, "error")

I could not find a way to prevent entering anything after entering the domain : for example : – “http://www.mydomain.uk/whateverthing.ext” i want to stop entering the “whateverthing after entering the domain . I could not figure out a way to solve this issue . can anyone give me a help?”(this will include validating the URL as well)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:49:13+00:00Added an answer on May 27, 2026 at 4:49 pm

    OK, so you want two things:

    • validate the hostname;
    • validate that the part after the /, if / there is, is empty.

    You can proceed as such:

    • validate your input against ^https?://([a-z0-9-]+(?:\.[a-z0-9-]+)*)/?(.*);
    • if the above does not match, you have an invalid URL;
    • grab group 2: if non empty, it means a non empty path, invalid URL;
    • grab group 1 and split it against \..
    • verify whether all groups are of length <= 255 and match ^[a-z0-9]+(-[a-z0-9]+)*$: if one doesn’t, invalid URL.

    And that doesn’t take IP addresses in the hostname part…

    I am surprised anyhow that jQuery doesn’t have methods to check for that. Have you looked?

    Edit: it has: http://docs.jquery.com/Plugins/Validation/Methods/url

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .
When I write a regular expression like: var m = /(s+).*?(l)[^l]*?(o+)/.exec(this is hello to
I'm just learning scala, and I wrote the hello,world program like this: object HelloWorld
I wrote some simple program int main(){ printf(hello word!); return 0; } I compiled
Hello StackOverflow community, Using Google App Engine, I wrote a keyToSha256() method within a
hello i want to get startet with programming with WIN32, therefore i wrote a
I wrote a hello world application. I want it so when the close button
I wrote a simple 'Hello, world' application in C++ using Visual Studio 2008. I
I wrote simple script test echo hello #<-- inside test if I press one
I wrote some jQuery to select the cells from a table with a certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.