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 523521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:28:16+00:00 2026-05-13T08:28:16+00:00

What would be a regular expression which I can use to match a valid

  • 0

What would be a regular expression which I can use to match a valid JavaScript function name…

E.g. myfunction would be valid but my<\fun\>ction would be invalid.

[a-zA-Z0-9_])?
  • 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-13T08:28:16+00:00Added an answer on May 13, 2026 at 8:28 am

    [EDIT] See @bobince’s post below for a more correct and thorough answer. This answer has been retained for reference and edited to be less wrong.

    A valid name in JavaScript must start with a Unicode letter (\p{L}), dollar sign, or underscore then can contain any of those characters as well as numbers, combining diacritical (accent) characters, and various joiner punctuation and zero-width spaces. Additionally, it cannot be a word reserved by the JavaScript language (e.g. abstract, as, boolean, break, byte, case, etc).

    A full regular expression solution would be quite complicated in plain JavaScript but the XRegExp Unicode plugin could greatly simplify the task. This online function name tester might also be useful.

    [ORIGINAL] Here is an incomplete regular expression, using only the US ASCII letters:

    var fnNameRegex = /^[$A-Z_][0-9A-Z_$]*$/i;
    

    You also must check that it doesn’t match any reserved words (e.g. abstract, boolean, break, byte, …, while, with, etc). Here’s a start for that list, and an example function:

    var isValidFunctionName = function() {
      var validName = /^[$A-Z_][0-9A-Z_$]*$/i;
      var reserved = {
        'abstract':true,
        'boolean':true,
        // ...
        'with':true
      };
      return function(s) {
        // Ensure a valid name and not reserved.
        return validName.test(s) && !reserved[s];
      };
    }();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 260k
  • Answers 260k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Doesn't get much easier than <input type='button' ... /> <br… May 13, 2026 at 11:29 am
  • Editorial Team
    Editorial Team added an answer In the project properties, you can turn off different types… May 13, 2026 at 11:29 am
  • Editorial Team
    Editorial Team added an answer jQuery('li:has(a)') .css('cursor', 'pointer') .hover(function(){ jQuery(this).addClass('highlight'); }, function(){ jQuery(this).removeClass('highlight'); }) .click(function(e){… May 13, 2026 at 11:29 am

Related Questions

I am trying to come up with a regular expression in Perl matching multiple
I have created a CLR in a SQL server 2005 database. It is a
Using JQuery, I'm extracting the value from what is essentially a query box for
Anyone have any opinions on whether or not IEquatable<T> or IComparable<T> should generally require
I would like a regular expression to match given a partial or camel cased

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.