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

  • SEARCH
  • Home
  • 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 7196027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:41:52+00:00 2026-05-28T20:41:52+00:00

I am working on MVC Razor. I face an issue to validate URL validation.

  • 0

I am working on MVC Razor. I face an issue to validate URL validation.

I need to do URL validation before inserting in temp DB.

I got a reference of http://www.regxlib.com/Search.aspx?k=&c=2&m=-1&ps=20

and found one nice validation pattern,

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?

While i work in MVC view, it gives me error so i have change it to

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@@?^=%&:/~\+#]*[\w\-\@@?^=%&/~\+#])?

i.e.

@@ instead of @

when it runs and if i see the console, i got the original one, so i think it is okay for me to do
@@ instead of @

But in console i got an error

enter image description here

can anyone tell me what is wrong with this, so got the error,

“invalid range in character class”

  • 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-28T20:41:53+00:00Added an answer on May 28, 2026 at 8:41 pm

    Easiest way to fix this: In the javascript validator, remove new RegExp() as well as the quotes, and add slashes at beginning and end, indicating a regex literal. Because your Regex is in a string, “\” is interpreted as a string escape, rather than a regex escape, essentially meaning all the “\” will be removed. You avoid that by not using a string, but a javascript regex literal:

    var urlregex = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
    

    If creating the expression using RegExp(), you’d have to use \\ in every place \ occurs.

    As mentioned in the comment, replace two & with & (double HTML encode on server you got the regex from). They’re not wrong in Regex syntax, but they do make the expression allow for ;, which isn’t allowed in a URL.

    Update/explanation

    The actual meaning of the error is that because javascript ignores all the backslashes in the string when creating the final regex, it turns into:

    /(http|ftp|https)://[w-_]+(.[w-_]+)+([w-.,@?^=%&:/~+#]*[w-@?^=%&/~+#])?/
    
    • The original [\w\-_] means “match any word (alphanumeric) character, a hyphen or an underscore”.
    • [w-_] means “match any character between “w” and “_”.

    But “w” actually comes after “_” (look at an ASCII/UTF-8 character table) meaning it’s an invalid range in the character class (“character class” = “collection of characters to match”)

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

Sidebar

Related Questions

I am working on my 1st mvc razor project. I set the project and
I am working on project using MVC 3.0(Razor framework). I am trying to get
i am working in asp.net mvc 3 web application which uses razor code. and
I am working on asp.net MVC 3 application. I have created a Razor view
I am working on MVC 4.0. I need to access my dropdown box Text
The DataAnnotations validator not working in asp.net mvc 4 razor view, when using the
Working on an ASP.NET MVC 3 (Razor) application, that's mainly concerned with UGC (user
I am working on a .NET MVC 3, razor site and I want to
I'm currently working with MVC 1.0 and have never worked with AJAX before and
I've got my little asp.net mvc app working as expected, however I'm building the

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.