Jump to content

[SOLVED] code issue 0 -1


purencool

Recommended Posts

Hi phpfreaks

 

This code should either find a . anywhere in the string to return nothing. Else  add . to the end.  I can not get it to work. Can any one see why?

thanks purencool

           
var mores =  win.search(/./)
            alert(mores)
          if( mores != -1 || 0){
                var returnValue = win;
            }else{
                returnValue = (win += ".") ;
            }
            return returnValue;

Link to comment
Share on other sites

Think your problem's here..

 

if( mores != -1 || 0){

 

Should just be:

 

if (mores != -1) {

 

Remember 0 is a valid match. Also if you were wanting to check against -1 or 0, you'd need to use:

 

if( mores != -1 || more != 0){

Link to comment
Share on other sites

You were right thanks I don't  what I was thinking when I wrote that.

But my issue was the regex and full stop. This fixed it.

 

            var mores =  win.search(/[.]/);
            if( mores != -1){
                var returnValue = win;
            }else{
                returnValue = (win += ".") ;
            }
            return returnValue;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.