Validate that username is at most 10 characters. Added Padding for username.

This commit is contained in:
Ibrahim Mkusa 2017-04-23 11:43:52 -04:00
parent 6bac96cfdb
commit c78c2fb872

View File

@ -61,11 +61,13 @@
'())) '()))
; creates the editing area as part of the parent "main-frame" define above. ; 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 ; TODO make label setable
(define input (new text-field% (define input (new text-field%
[parent main-frame] [parent main-frame]
[label "user"] [label "username "]
[callback text-field-callback] [callback text-field-callback]
)) ))
@ -198,7 +200,12 @@
(define (get-username) (define (get-username)
(define returned (get-text-from-user "Username set-up" "Please enter a username" (define returned (get-text-from-user "Username set-up" "Please enter a username"
main-frame "user" (list 'disallow-invalid) 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) (send input set-label returned)
returned) returned)