/    Sign up×
Community /Pin to ProfileBookmark

Hey guys,

My regex is non-existent right now as I just don’t have time to learn it, but have come across a need for only allowing a string to have 0-9, a-z, A-Z and _

how on earth would I right a regex statement to allow for this….it’s for a username input.

Thanks for any help.

CM

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@hyperliskMar 31.2006 — <i>
</i>function chackUsername(username){
var r = new RegExp("[a-z|A-Z|0-9|_]","ig");
for(var i=0;i&lt;username.length;i++){
if(! username.charAt(i).match(r)){
alert("Invalid username, please check your spelling!");
return false;
}
}
}

I'm pretty sure that will work.
Copy linkTweet thisAlerts:
@CrazyMerlinauthorMar 31.2006 — thx dude!

I know I must learn it one day...but today just isn't it.

thx again
Copy linkTweet thisAlerts:
@gphApr 01.2006 — I prefer hyperlisks RegExp because it's easier to read but, just so you know, w does the same thing.
Copy linkTweet thisAlerts:
@gphApr 01.2006 — I wasn't thinking straight in my last post. You need to look for [B]non[/B]-word characters. This is true if str contains non-word characters.

/W/.test(str)
Copy linkTweet thisAlerts:
@hyperliskApr 01.2006 — I never really looked into the special codes for RegExp's. The only ones I know are ^ and $. Lol.
×

Success!

Help @CrazyMerlin 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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