Moon Chow wrote:
Hi,
Please don't top post. Quote what you are responding too, trim quotes
and put your reply immediately below the quote it refers to.
thanks for the regx expression; unfortunately I'm a total newbie at JS, and
don't know how to integrate it into my form-checker. could i set up this
function to run "onblur" for each of my form entries, to halt form execution
if it detects "http"...? If so, how can I set up the expression to test
specific field contents; example if the field in question is "form1.name" ?
Do not use onblur with an alert for form validation - it annoys the hell
out of users. If you want to report errors while the form is being
completed, write an error message to the page.
And remember that forms must *always* be validated at the server,
client-side validation is unreliable and is only for user convenience.
e.g.
<title>Error message play</title>
<style type="text/css">
.errMsg {color: red; font-weight: bold; background-color: #fee;}
</style>
<script type="text/javascript">
function hasStr(srcString, testString)
{
var re = new RegExp(testString, 'i');
return (re.test(srcString));
}
function checkStr(el, str, bool)
{
if (el.value && hasStr(el.value, str) != bool){
showErr(el, 'Input must ' + ((bool)?'':'not')
+ ' contain ' + str);
} else {
showErr(el, '');
}
}
function showErr(el, erString)
{
if (el.name && document.getElementById){
var erEl = document.getElementById(el.name + '.msg');
if (erEl) erEl.innerHTML = erString;
}
}
</script>
<div>
<label for="i-01">This input must not have 'http'<br>
<input name="i-01"
onblur="checkStr(this,'http',false);"></label><span
class="errMsg" id="i-01.msg"></span><br>
<label for="i-02">This input must have 'Nancy'<br>
<input name="i-02"
onblur="checkStr(this,'Nancy',true);"></label><span
class="errMsg" id="i-02.msg"></span>
</div>
The above functions would normally be put inside a single object and
called as part of a much more generic form validation process, but you
get the idea.
[...]
--
Rob