By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

I'm a VB/Notes guy looking for the equivalent of Like and/or @Contains in JS

P: 4
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!
Apr 22 '08 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

you may use a regExp for this, like:

Expand|Select|Wrap|Line Numbers
  1. var s = 'my.string';
  2.  
  3. var val = /[.]/g.test(s);
  4.  
  5. // now val is true here
  6.  
have a look here for more details. you could even use indexOf();

Expand|Select|Wrap|Line Numbers
  1. var s = 'my.string';
  2.  
  3. var val = s.indexOf('.');
  4.  
  5. // val is 2 here ... when there is no . then it would be -1
  6.  
kind regards
Apr 22 '08 #2

P: 4
hi ...

you may use a regExp for this, like:

Expand|Select|Wrap|Line Numbers
  1. var s = 'my.string';
  2.  
  3. var val = /[.]/g.test(s);
  4.  
  5. // now val is true here
  6.  
have a look here for more details. you could even use indexOf();

Expand|Select|Wrap|Line Numbers
  1. var s = 'my.string';
  2.  
  3. var val = s.indexOf('.');
  4.  
  5. // val is 2 here ... when there is no . then it would be -1
  6.  
kind regards
thank you
here is what I have
Expand|Select|Wrap|Line Numbers
  1.            var dcm = /^.$/
  2.             form = document.forms[0];
  3.             objField = form.QtyLb;
  4.             if( objField.match(dcm)) {
  5.                         objField.focus();
  6.                         alert("Please adjust your weight to whole number.");
  7.                         return false; 
  8.             }
how would I go about plugging in what you offered given the input validation I have?
Apr 22 '08 #3

gits
Expert Mod 5K+
P: 5,390
what do you really want to check? your current regEx matches a single point ... ?
Apr 22 '08 #4

P: 4
what do you really want to check? your current regEx matches a single point ... ?
If what is entered has a decimal point. That is what I'm looking to check for.
Apr 23 '08 #5

gits
Expert Mod 5K+
P: 5,390
the regExp:

Expand|Select|Wrap|Line Numbers
  1. var re = /[.]/;
  2.  
matches in case there is any decimal-point in the string ... and you should check the value of your field ... not the field itself:

Expand|Select|Wrap|Line Numbers
  1. objField.value
kind regards
Apr 23 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.