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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mastro78
    New Member
    • Sep 2007
    • 4

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

    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!
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    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

    Comment

    • mastro78
      New Member
      • Sep 2007
      • 4

      #3
      Originally posted by gits
      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 you
      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?
      Last edited by gits; Apr 22 '08, 08:29 PM. Reason: added code tags

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        what do you really want to check? your current regEx matches a single point ... ?

        Comment

        • mastro78
          New Member
          • Sep 2007
          • 4

          #5
          Originally posted by gits
          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.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            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 regards

            Comment

            Working...