/    Sign up×
Community /Pin to ProfileBookmark

How do I create regular expression of only “a-z”, “0-9”, “-“, “_” and “.”

Hello!
I’m creating a BuddyBoss sign on page with a “nickname” field. BuddyBoss requires only the following characters for the “nickname” field:

“a-z”, “0-9”, “-“, “_” and “.”

How can I create a regular expression for this?
Any other characters need to be excluded.
(Please note, the “a-z” can be upper or lower case.)
Thank you for your help!

to post a comment
RegExWordPress

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 13.2023 — /^[a-zA-Z0-9_.-]+$/ ... I think?

Assumption: you want the whole string to match (thus I anchored it to the start and end with ^ and $), and be at least one character long (the '+' character after the bracketed expression). If that's not exactly what you want, then we'll need more data. :)
Copy linkTweet thisAlerts:
@cootheadFeb 13.2023 — Hi there rshaules,

here is @NogDog's assumption put to the test...

<i>
</i>(function() { <br/>
var pattern = /^[A-Za-z0-9_.-]+$/;
var str1 = 'Aa09._-Q';
var str2 = 'Aa?09._-Q';
<br/>
if ( str1.match( pattern )){
console.log( true );
}
else {
console.log( false );
}

if ( str2.match( pattern )){
console.log( true );
}
else {
console.log( false );
}
}());


[i]coothead[/i]
×

Success!

Help @rshaules spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...