Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

adding keyboard enter key to regular expression in JavaScript function to validate textarea

Hi experts,

I'm using JavaScript and a regular expression to validate input in a TextArea.

Here is my working fiddle:
https://jsfiddle.net/r2d22k18/jj27pLbm/1/

User generated image
When a user types in /> inside the text area, they get the message "Sorry that input is invalid"

User generated image
When a user types in </ inside the text area, they get the message "Sorry that input is invalid"

User generated image
These two case are correct and validation message should show up. Any other input is valid.

But I noticed when I press the Enter key on my keyboard that is also failing the validation and causing the message "Sorry that input is invalid" to display.

User generated image
How do I fix my example, so pressing the Enter Key on my board doesn't cause the validation to fail?
ASKER CERTIFIED SOLUTION
Avatar of Swapnil
Swapnil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maqskywalker
maqskywalker

ASKER

thanks. great solution.