Page 1 of 1
Number of chars
Posted: Sat Aug 10, 2019 11:04 am
by Quinton B.
Good day,
I've been trying to use the following code:
Code: Select all
get the number of chars of field "RegisterPassword"
in order to gather how many characters are within the field (eg. A,B,C/etc) and
Code: Select all
get the number of nums of field "RegisterPassword"
in order to gather how many numbers are within the field.
What should I do, or try to do since this is an invalid statement?
Re: Number of chars
Posted: Sat Aug 10, 2019 11:48 am
by Klaus
Hi Quinton,
maybe some nifty REGEX will solve this, but sincxe I still have not the slightest idea about
that stuff, I would probably use a "repeat for each char tChar...if tChar is a number then
add 1 to tNumbers..." loop.
Best
Klaus
Re: Number of chars
Posted: Sat Aug 10, 2019 5:17 pm
by FourthWorld
What is the total length of the field contents, and is there any structure to the placement of numbers in the text?
Re: Number of chars
Posted: Sat Aug 10, 2019 6:13 pm
by [-hh]
Quinton,
after reading your question a second time I think you look for counting the number of digits 0-9 rather than "numbers", in order to check for a certain "password-rule".
Here is a stack that does even more such password rules:
viewtopic.php?p=182110#p182110.
And you could only count the number of digits as follows (similar to what Klaus said):
Code: Select all
function numOfDigits str
put 0 into cntr
repeat for each char c in str
if c is in "0123456789" then add 1 to cntr
end repeat
return cntr
end numOfDigits
Re: Number of chars
Posted: Sat Aug 10, 2019 9:28 pm
by Quinton B.
I believed I've confuzzeled myself.
My criteria is for the password to be 10 chars long, 4 chars (2 Capital and 2 Lower Case), 4 numbers, and 2 Special Characters.
I've tried already to modify your code but honestly get lost as I don't really know how it works:
Code: Select all
function numOfDigits str
put 0 into cntr
repeat for each char c in str
if c is in "0123456789" then add 1 to cntr
end repeat
return cntr
end numOfDigits
Re: Number of chars
Posted: Sat Aug 10, 2019 10:50 pm
by [-hh]
You could use stack "passwordRules" from "Sample Stacks" with the following settings
(where fld "Xxtra" contains
your allowed special chars).

- Ready for input of a password to check.
Then you can check whether a given password fulfils your rule or you can generate a random password that fulfils your rules.

- Generated random password.
What you need for use in your stack is the script of btn "Check" (the options and the fields hardcoded) or, for generating, the script of btn "Generate" (the options and the fields hardcoded).