Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

I have a page with a textbox where a user is supposed to enter a 24 character registration code. I used maxlength to limit the user to enter 24 characters.

The registration codes are typically given as groups of characters separated by dashes, but I would like for the user to enter the codes without dashes.

How can I write a JavaScript code to check that the user inputs do not contain dashes, or better yet, only contains alphanumeric characters?

1 Answer

0 votes
by (13.1k points)

You can check if the users input contains alphanumeric characters by using regular expressions by using like /hello/g.test(your_string) or you can use indexOf string like this:

if (your_string.indexOf('hello') > -1)

{

  alert("hello found inside your_string");

}

Want to be a full stack developer? Check out the full stack developer course from Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...