Conditions > Widget contains letters > shorter way

advanced-prototyping

#1

Hey everyone,

i created a password strength bar to show fullfilled password restrictions like lowercase, uppercase, numbers and special characters. I did it very dirty with a long list of “contains”-arguments:

Is there a better way to short this? I tried to create a list of values in one line e.g. “A”,“B”,“C”… but this doesn’t work because axure idenfitied the whole “A”,“B” as the value… and not each letter separated.

Thank you for your further help.

Regards


#2

You’re also only detecting upper-case characters, you’d need another 26 for lower-case too. But luckily there is a better way:


EDIT: I think I misunderstood what you’re asking. You want to check if it contains any upper-case letters? Not just letters?


#3

Oh sorry, maybe i wrote my question a little bit cryptic.

My problem is to create a divided view on the password strength like this:


That means I have to divide between uppercase, lowercase, numbers and special characters. Thats why the given functions is numeric, is alpha-numeric, is alpha are not enough.

I tried also the option “is one of” but that was not the right way because this function looks only for any of this stuff, not like the contain function


#4

I have created what you are talking about and I could not get the “is one of” to work either. It was a huge pain to create. I believe it might be possible to do through “is one of” based on repeater content.

  1. Create a hidden repeater or custom astericks through a repeater.
  2. On ‘KeyUp’ add a row to the repeater based on the key pressed
  3. The “OnItemLoad” of the repeater would call out the “is one of” functions.

This is a possible solution I can think of to get access to the “is one of” function, although you would have to clear all content in the password field OnFocus to reset the repeater and allows only backspacing (removing isLast with in repeater) within the password field.

Good luck. Hope that helps!


#5

Hi!

This is shorter but a bit more complex. Upon validation, the OnTextChange handler (or, in the second example, the OnClick handler) loops through each character in the string.

Since you are evaluating only one character of the password at a time - using the charAt(number) function - the conditions become much easier. The following condition tests whether the character at the first position (0) of the password is uppercase, where pwd is a local variable referring to the text in the password field:

If ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’ contains [[pwd.charAt(0)]]

The code, however, instead of using a hardcoded number in the charAt() function like 0, uses a variable that increases by one as it tests each letter, thus iterating through the whole password string. This “loop” also tests for the other required conditions.

This uses the Move By “function” call to do the actual evaluation. You could add length requirements to this “function.”

Here’s a live sample that requires uppercase, lowercase, numeric, and certain allowed special characters. It rejects the password if any illegal character is entered.

File: checkPassword.rp (85.8 KB)


Check if a string contains ONLY specific characters
closed #6

unlisted #7