<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D51Y00006qa2K5SAIOkta Classic EngineOkta Integration NetworkAnswered2025-03-30T09:09:38.000Z2019-10-24T15:11:15.000Z2021-01-11T21:06:24.000Z

2ayev (2ayev) asked a question.

Regular expression for Okta email validation?

Is there a regular expression that enforces/validates an email to the Okta email naming rules..i.e. those expressed here:

 

https://help.okta.com/en/prod/Content/Topics/Directory/Reference_Directories.htm*targetText=Email%20top%2Dlevel%20domains%20(the,user%20names%20or%20email%20addresses.

 

Thanksinadvance

 

Scott


  • oxptp (oxptp)

    I put together a regex below that is based off of a combination of RFC5322 + Okta documentation, excluding the characters: ' ` ~. Regex is never perfect with email validation, and my example will not cover every possibility, but it should help accomplish your goal. This is written to conform to JavaScript regex rules so if you need it in another language just let me know!

     

    (?:[a-z0-9!#$%&*+/=?^_{|}-]+(?:\.[a-z0-9!#$%&*+/=?^_{|}-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

    Expand Post
    Selected as Best
  • oxptp (oxptp)

    I put together a regex below that is based off of a combination of RFC5322 + Okta documentation, excluding the characters: ' ` ~. Regex is never perfect with email validation, and my example will not cover every possibility, but it should help accomplish your goal. This is written to conform to JavaScript regex rules so if you need it in another language just let me know!

     

    (?:[a-z0-9!#$%&*+/=?^_{|}-]+(?:\.[a-z0-9!#$%&*+/=?^_{|}-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

    Expand Post
    Selected as Best
  • GregA.53180 (Customer)

    According to https://help.okta.com/en/prod/Content/Topics/Directory/Reference_Directories.htm and especially that domains must have a minimum length of 2 characters I've adjusted @oxptp (oxptp)​ regex:

     

    (?:[a-z0-9!#$%&*+/=?^_{|}-]+(?:\.[a-z0-9!#$%&*+/=?^_{|}-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]?[a-z0-9])+|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

    Expand Post
This question is closed.
Loading
Regular expression for Okta email validation?