I'm working on Input Validation using the JS Header in my Notes app. I originally had formulas in Notes that was doing this, but now I've taken it to the web. So, after redoing the majority of the formulas in JS, I came to one input validation that wasn't within the realm of comparisons in JS. I'm looking that if mystr contains "." then alert, etc. But I can't seem to find anything in JS that is similar. Please advise. Thank you for your help!
I'm a VB/Notes guy looking for the equivalent of Like and/or @Contains in JS
Collapse
X
-
hi ...
you may use a regExp for this, like:
[CODE=javascript]var s = 'my.string';
var val = /[.]/g.test(s);
// now val is true here
[/CODE]
have a look here for more details. you could even use indexOf();
[CODE=javascript]var s = 'my.string';
var val = s.indexOf('.');
// val is 2 here ... when there is no . then it would be -1
[/CODE]
kind regards -
thank youOriginally posted by gitshi ...
you may use a regExp for this, like:
[CODE=javascript]var s = 'my.string';
var val = /[.]/g.test(s);
// now val is true here
[/CODE]
have a look here for more details. you could even use indexOf();
[CODE=javascript]var s = 'my.string';
var val = s.indexOf('.');
// val is 2 here ... when there is no . then it would be -1
[/CODE]
kind regards
here is what I have
[CODE=javascript] var dcm = /^.$/
form = document.forms[0];
objField = form.QtyLb;
if( objField.match( dcm)) {
objField.focus( );
alert("Please adjust your weight to whole number.");
return false;
}[/CODE]
how would I go about plugging in what you offered given the input validation I have?Comment
-
the regExp:
[CODE=javascript]
var re = /[.]/;
[/CODE]
matches in case there is any decimal-point in the string ... and you should check the value of your field ... not the field itself:
[CODE=javascript]objField.value[/CODE]
kind regardsComment
Comment