Validation Function: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Added category links.) |
m (added a workaround for syntax highlighting) |
||
Line 21: | Line 21: | ||
!define ALPHA "abcdefghijklmnopqrstuvwxyz " | !define ALPHA "abcdefghijklmnopqrstuvwxyz " | ||
!define NUMERIC "1234567890" | !define NUMERIC "1234567890" | ||
!define SPECIAL "~!@#$%^&*()_+|`\=-}{$\":?><][';/.," | !define SPECIAL "~!@#$%^&*()_+|`\=-}{$\":?><][';/.," # workaround for syntax highlighting - ' | ||
;Push "value to check" | ;Push "value to check" |
Revision as of 20:30, 9 June 2005
Author: dselkirk (talk, contrib) |
Description
Allows you to validate a string with a custom criteria. This means you can validate a string to only contain numbers, or just letters, or a combination of both. Enjoy!
Example of Usage
Section Push "This is a test" Push "${ALPHA}" Call Validate Pop $0 MessageBox MB_OK $0 SectionEnd
The Function
!define ALPHA "abcdefghijklmnopqrstuvwxyz " !define NUMERIC "1234567890" !define SPECIAL "~!@#$%^&*()_+|`\=-}{$\":?><][';/.," # workaround for syntax highlighting - ' ;Push "value to check" ;Push "comparisonlist" Function Validate Push $0 Push $1 Push $2 Push $3 ;value length Push $4 ;count 1 Push $5 ;tmp var 1 Push $6 ;list length Push $7 ;count 2 Push $8 ;tmp var 2 Exch 9 Pop $1 ;list Exch 9 Pop $2 ;value StrCpy $0 1 StrLen $3 $2 StrLen $6 $1 StrCpy $4 0 lbl_loop: StrCpy $5 $2 1 $4 StrCpy $7 0 lbl_loop2: StrCpy $8 $1 1 $7 StrCmp $5 $8 lbl_loop_next 0 IntOp $7 $7 + 1 IntCmp $7 $6 lbl_loop2 lbl_loop2 lbl_error lbl_loop_next: IntOp $4 $4 + 1 IntCmp $4 $3 lbl_loop lbl_loop lbl_done lbl_error: StrCpy $0 0 lbl_done: Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Exch 2 Pop $7 Pop $8 Exch $0 FunctionEnd