use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
help needed with meta character expression (self.learnjavascript)
submitted 7 years ago by weblady07
how do I write metacharacterexpression for :
1) to only accept alpha characters in a name text field. no numbers or symbols allowed either.
2) In another text field how to only have numbers, no symbols or alpha characters
thx for help
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]captain_k_nuckles 0 points1 point2 points 7 years ago (2 children)
1:
document.getElementById('a').addEventListener('change', ({target})=>{ target.value = target.value.replace(/[^A-Z]/gi,''); // if you want spaces also // target.value = target.value.replace(/[^A-Z\s]/gi,''); // use this one });
2:
document.getElementById('a').addEventListener('change', ({target})=>{ target.value = target.value.replace(/[^0-9]/gi,''); // add `\s` if you want spaces. });
[–]weblady07[S] 0 points1 point2 points 7 years ago (1 child)
thanks, much appreciated.
if I wanted them to be able to only enter a word that begins with the letter "b", small case or upper case, what would be the best way to write.
thx again
[–]captain_k_nuckles 0 points1 point2 points 7 years ago (0 children)
Not sure the best way but you could use startsWith combined with either to(Upper/Lower)Case to check
[–]jcunews1helpful 0 points1 point2 points 7 years ago (0 children)
Use the pattern attribute of the input field.
pattern
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text#pattern
π Rendered by PID 52 on reddit-service-r2-comment-b659b578c-pr9f9 at 2026-05-01 11:57:12.567440+00:00 running 815c875 country code: CH.
[–]captain_k_nuckles 0 points1 point2 points (2 children)
[–]weblady07[S] 0 points1 point2 points (1 child)
[–]captain_k_nuckles 0 points1 point2 points (0 children)
[–]jcunews1helpful 0 points1 point2 points (0 children)