<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script type="text/javascript">
jQuery(function(){
$("#btn-search").click(function(){
$(".error").hide();
var hasError = false;
var searchReg = /^[a-zA-Z0-9-]+$/;
var searchVal = $("#search-text").val();
if(searchVal == '') { //пустая строка
$("#search-text").after('<span class="error">Please enter a search term.</span>');
hasError = true;
} else if(!searchReg.test(searchVal)) { //ошибка , не правильные симыолы
$("#search-text").after('<span class="error">Enter valid text.</span>');
$("#search-text").val()=''; //обнуляем строку
hasError = true;
}
if(hasError == true) {return false;}
else { // всё хорошо
$("#search-text").after('<span class="error">Search term accepted.</span>');
return false;
}
});
});
</script>
</head>
<body>
<form method="post" name="form1" action="">
<fieldset>
<div><label>Search:</label><input type="text" name="search-text" id="search-text" value="" size="32" /></div>
<div><label></label><input type="submit" value="Submit" id="btn-search" /></div>
</fieldset>
</form>
</body>
</html>