PDA

View Full Version : textarea validation


ebco
03-05-2003, 05:48 AM
Hi,

I have a textarea in which I have to check if anyone just giving /pressing Enter key in it because i want to validate that box it should not be keep blank

What is the way to validate this type of situation?

Philip M
03-05-2003, 07:26 AM
function checkifentry {
if (/^\s*$/.test(yourtextbox.value)){alert ('You have not entered anything in the textbox!)}
}

which can be called by onsubmit.

This simply checks to see if the box is completely blank -
but even a single character will pass the test and return true.

ebco
03-05-2003, 09:13 AM
gr8!

Can u explain me te regular expretion which u mentioned?

Philip M
03-05-2003, 06:51 PM
^ matches the start of the input or line

\s matches a single whitespace character including space, tab, carriage return etc.

* matches zero or more instances of the preceding character

$ matches the end of the line or input

So ..... if the textbox value consists of nothing, or just spaces and other whitespace charcaters, return true and call the alert.