Validation of textarea
How to do I validate a textarea in a form? i.e, it should not be empty or have any new lines, and if so raise an alert. Code: <script> function val() { //ifnewline found or blank raise an alert } </script> <form> <textarea name = "pt_text" rows = "8" cols = "8" class = "input" WRAP ></textarea> <input type=""button" onclick="val();" </form> The easiest way I could think of: function validate() { var val = document.getElementById('textarea').value; if (/^\s*$/g.test(val) || val.indexOf('\n') != -1) { alert('Wrong content!'); } } Sarfraz Try this: <textarea id="txt" name = "pt_text" rows = "8"