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 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

Related Questions

I thought this code would work, but the regular expression doesn't ever match the
How would one write a regular expression to use in Python to split paragraphs?
How would you write a regular expression to convert mark down into HTML? For
Could someone show me a regular expression that would look through this document and
I'm new to regular expressions and would appreciate your help. I'm trying to put
I am battling regular expressions now as I type. I would like to determine
Would it not make sense to support a set of languages (Java, Python, Ruby,
Would it be possible to print Hello twice using single condition ? if condition
Would it be possible to show an image in full screen mode using silverlight.
Would the following SQL remove also the index - or does it have to

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.