You are putting the bar upside down. In regular expressions the bar \ in front of a character indicates that that character will have a special meaning instead of its literal meaning (for example \n
does not mean the character n
but the new line).
So, in your regular expression it should be \ instead of /, and it would be something like this /^\s+$/
, so the code would look like this:
if( $("#comments").val() == "" || $("#comments").attr("value").match(/^\s+$/)){
$("#comments").focus().after("<span class='error'>This field is required.</span>");
return false;
}