Old 3rd December 2015, 08:29   #1
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Question String length

i am trying to verify if an input field has at least X number of characters in it,
i need to replace this line in the script below this line ${CheckUserEmailAddress} "$1" "$R1"
with an input string length check; instead of email check i have for for the second field (its not a password field!)

after the email is verified; i just need to verify the next field has at least 8 characters before moving on to the next check,

any advice?

TIA
Chris

PHP Code:
Function CustomCreate
    nsDialogs
::Create 1018
    Pop $Dialog2
    
${If} $Dialog2 == error
        Abort
    
${EndIf}
        ${
NSD_CreateGroupBox5u 0u 96.555u "Order Details"
        
Pop $GroupBox1
        SendMessage $GroupBox1 
${WM_SETFONT$hCtl_TestDesigner_Font1 0        
        
${NSD_CreateLabel15 31 2012u "Email:"
        
Pop $0
        
${NSD_CreateText120 26 5013u $Text2_State
        Pop $Text
        
${NSD_CreateLabel15 55 2012u "Code"
        
Pop $1
        
${NSD_CreateText120 50 5013u $Text2_State
        Pop $Text2
        nsDialogs
::Show
FunctionEnd

Function CustomLeave
         
${NSD_GetText$Text $0
             
${CheckUserEmailAddress"$0" "$R0"
             
StrCmp $R0 "1" 0 next
             MessageBox MB_OK 
"invalid email"
             
Abort
         next
:
         ${
NSD_GetText$Text2 $1
             
${CheckUserEmailAddress"$1" "$R1"
             
StrCmp $R1 "1" 0 next2
             MessageBox MB_OK 
"invalid code"
             
Abort
         next2
:
FunctionEnd 
MyPC8MyBrain is offline   Reply With Quote
Old 3rd December 2015, 13:39   #2
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 886
http://nsis.sourceforge.net/Docs/Chapter4.html#StrLen.
http://nsis.sourceforge.net/Docs/Chapter4.html#intcmp.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 3rd December 2015, 13:44   #3
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thank you Jason,
i saw that earlier; i couldn't figure how to incorporate it with length check,
i wasn't sure if its the right way about this; ill give it another go,

ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 3rd December 2015, 13:46   #4
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 886
I edited my post, you need IntCmp to do the actual length check.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 3rd December 2015, 14:38   #5
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thank you Jason
what am i missing here?

PHP Code:
         ${NSD_GetText$Text2 $1
             StrLen 
$"11111111" # =8
             
Pop $R1
             IntCmp $R1 8 ok less more
             less
:
             
DetailPrint "$$R1 < 8"
             
MessageBox MB_OK "invalid"
             
Abort
             more
:
             
DetailPrint "$$R1 > 8"
             
Goto done
             ok
:
             
DetailPrint "$$R1 == 8"
             
Goto done
             done

MyPC8MyBrain is offline   Reply With Quote
Old 3rd December 2015, 14:58   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,263
Why do Pop $R1 ? The length is in $1 !

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd December 2015, 15:10   #7
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
in this way it all pass valid blindly

PHP Code:
         ${NSD_GetText$Text2 $1
             StrLen 
$"11111111" # =8
             
Pop $1
             IntCmp 
$1 8 ok less more
             less
:
             
DetailPrint "$$1 < 8"
             
MessageBox MB_OK "invalid"
             
Abort
             more
:
             
DetailPrint "$$1 > 8"
             
Goto done
             ok
:
             
DetailPrint "$$1 == 8"
             
Goto done
             done

MyPC8MyBrain is offline   Reply With Quote
Old 3rd December 2015, 15:56   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,263
Nobody told you to pop at all. The result is stored directly in the variable!

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd December 2015, 16:28   #9
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
even without the Pop; its still a no go for me
MyPC8MyBrain is offline   Reply With Quote
Old 3rd December 2015, 16:40   #10
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,263
After 'StrLen $1 "11111111"' $1 is always going to be 8. You are retrieving the text with ${NSD_GetText} and then throw away this text on the next line when it is overwritten by the result of StrLen. The syntax of StrLen is: StrLen $Output "Input", if you cannot understand this basic instruction then you might want to take a look at other installers like Inno Setup with less focus on pure scripting...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd December 2015, 23:54   #11
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Wink

Thank you Andres,
that is exactly what i was seeing earlier; i was always getting 8 for result,
i had to walk away for a bit as i was getting frustrated with this not working for me;

but... after rebooting my system i finally got it right

PHP Code:
             ${NSD_GetText$Text2 $1
             StrLen $R1 
"$1"
             
StrLen $R2 '11111111'
             
IntCmp $R1 $R2 ok less more
             less
:
             
MessageBox MB_OK "Invalid"
             
Abort
             more
:
             Goto 
done
             ok
:
             Goto 
done
             done

im still a newbie struggling with allot to pickup in a very short amount of time,
it is challenging; but i am learning, you and Jason been great resource throughout this learning curve,

ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 4th December 2015, 02:51   #12
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 886
You can optimize this even more by removing the second StrLen:
PHP Code:
${NSD_GetText$Text2 $1
StrLen $R1 
"$1"
IntCmp $R1 8 ok less more
less
:
MessageBox MB_OK "Invalid"
Abort
more
:
Goto 
done
ok
:
Goto 
done
done


"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 4th December 2015, 03:51   #13
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thumbs up

Nice!
MyPC8MyBrain is offline   Reply With Quote
Old 4th December 2015, 07:32   #14
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
quick question,
my nsDialogs seem to get stuck after submit comes with error,
(from incorrect email address or something expected)
the dialog input becomes locked for editing; i have to go back a page then forward again;
why is that? am i missing a refresh or something?

TIA
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 4th December 2015, 10:37   #15
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 886
Really? See if this works for you (it works for me):

PHP Code:
Name "Test"
OutFile "test.exe"

RequestExecutionLevel User

!include "MUI2.nsh"

Var Dialog2
Var GroupBox1
Var Text
Var Text2

page custom CustomCreate CustomLeave
!insertmacro MUI_PAGE_COMPONENTS

!insertmacro MUI_LANGUAGE "English"

Section
SectionEnd

Function CustomCreate
  nsDialogs
::Create 1018
  Pop $Dialog2
  
${If} $Dialog2 == error
    Abort
  
${EndIf}
  ${
NSD_CreateGroupBox5u 0u 96.555u "Order Details"
  
Pop $GroupBox1
  
${NSD_CreateLabel15 31 2012u "Email:"
  
Pop $0
  
${NSD_CreateText120 26 5013u "1"
  
Pop $Text
  
${NSD_CreateLabel15 55 2012u "Code"
  
Pop $1
  
${NSD_CreateText120 50 5013u "2"
  
Pop $Text2
  nsDialogs
::Show
FunctionEnd

Function CustomLeave
  
${NSD_GetText$Text $0
  MessageBox MB_OK 
"invalid email, |$0|"
  
${NSD_GetText$Text2 $1
  MessageBox MB_OK 
"invalid code, |$1|"
  
Abort
FunctionEnd 
Just on another note, also learn how to indent your code properly, it makes it easier to read. So my example would look like this:

PHP Code:
Function something
  
${NSD_GetText$Text2 $1
  StrLen $R1 
"$1"
  
IntCmp $R1 8 ok less more
  less
:
    
MessageBox MB_OK "Invalid"
    
Abort
  more
:
    Goto 
done
  ok
:
    Goto 
done
  done
:
FunctionEnd 

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 4th December 2015, 12:25   #16
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thank Jason
points taken!

the code you posted works ok for me too;
the issue i believe is with next step i have in the function,

i send the input out; if it passes your off to the next page;
if response comes back invalid; the input become locked,

PHP Code:
inetc::POST "" "http://..."
  
Pop $1
  FileOpen 
$$"r"
  
FileRead $$3
  FileClose 
$2
${If} $== 'INVALID'
    
MessageBox MB_OK|MB_ICONEXCLAMATION "Invalid"
    
IntOp $count $count 1
    IntCmp $count 3 0 
continue 0
    MessageBox MB_OK
|MB_ICONSTOP "Invalid, Installer will  now exit."
    
quit
  
continue:
    
Abort
${EndIf} 
(yes, there is a counter var on OnInit)
i think i need to sent it back to the previous page after failure;
but thats on page create; and this is on page leave,
i have nothing on leave page to restart the loop from again,
MyPC8MyBrain is offline   Reply With Quote
Old 4th December 2015, 23:34   #17
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 886
So which function is that code in? It's unwise to use abort within a Create function. Putting up the leave function and the next page's create function will help greatly.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 5th December 2015, 02:36   #18
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thank you very much Jason,

that bit is the second part of - on page leave, its not on page create;

i take the email input and code; then submit it for verification online,
the return token is then compared for false positive with that bit;
all still within page leave function,

the abort is there to end the loop and go again if the local basic input check fails,

ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 5th December 2015, 03:10   #19
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 886
Ok, you will have to do some troubleshooting. Start commenting out commands one at a time until it works, then start uncommenting them one at a time until it fails. This will lead to the command that's causing it to fail. Once you can control a failure, then you can find a solution to it.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 5th December 2015, 06:32   #20
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
i know where the issue is; its with continue: -> Abort
instead of aborting i need it to goto the start again;
but aborting there doesn't send me to start because im already on page leave instructions,
MyPC8MyBrain is offline   Reply With Quote
Old 5th December 2015, 06:53   #21
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
well...
i worked it out with RelGotoPage
MyPC8MyBrain is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump