From c78c2fb872413231b787eee60ea7df568bc80f1d Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sun, 23 Apr 2017 11:43:52 -0400 Subject: Validate that username is at most 10 characters. Added Padding for username. --- Hermes/GUI.rkt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Hermes/GUI.rkt b/Hermes/GUI.rkt index 25a4060..41dbd29 100644 --- a/Hermes/GUI.rkt +++ b/Hermes/GUI.rkt @@ -61,11 +61,13 @@ '())) ; creates the editing area as part of the parent "main-frame" define above. - ; initially labelled "Username:" + ; initially labelled "Username:" + ; NOTE: we pad label with additional spaces so we don't have to recompute + ; the window dimensions to fit the new label (the actual username) ; TODO make label setable (define input (new text-field% [parent main-frame] - [label "user"] + [label "username "] [callback text-field-callback] )) @@ -198,7 +200,12 @@ (define (get-username) (define returned (get-text-from-user "Username set-up" "Please enter a username" main-frame "user" (list 'disallow-invalid) - #:validate string? )) + #:validate + (lambda (input) + (if (and (string? input) (<= (string-length input) 10) + (>= (string-length input) 2)) + #t + #f)))) (send input set-label returned) returned) -- cgit v1.2.3