space between numbers, with a RegularExpression like this "^\d[\d ]*\d$"
or any other RegularExpression for that matter. On a #PB_EventType_Change.
The code below is for illustration purposes only.
Code: Select all
Enumeration
#str1
#bt1
#txt1
#win
#txt2
#Font_win
EndEnumeration
LoadFont(#Font_win, "", 10, #PB_Font_Bold)
Procedure Numbrs0T9wSpaces(nums.s)
CreateRegularExpression(1, "^\d[\d ]*\d$")
;Answr = MatchRegularExpression(1,GetGadgetText(#str1))
Answr = MatchRegularExpression(1,nums)
ProcedureReturn Answr
EndProcedure
flg=#PB_Window_SystemMenu|#PB_Window_ScreenCentered
OpenWindow(#win,0,0,310,160,"Limit Txtgadgt [0-9] and one space btwn nums",flg)
SetWindowColor(#win,$C5BE58 )
TextGadget(#txt1,30,25,240,20,"Country code and phone number ? ")
SetGadgetColor(#txt1,#PB_Gadget_BackColor,$C5BE58)
SetGadgetFont(#txt1, FontID(#Font_win))
StringGadget(#str1,30,40,240,20,"44 766 7123 8384")
TextGadget(#txt2,30,105,240,20,"",#PB_Text_Border|#PB_Text_Center)
SetGadgetFont(#txt2, FontID(#Font_win))
ButtonGadget(#bt1,90,70,135,20,"CheckRegEx")
SetGadgetFont(#bt1, FontID(#Font_win))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #bt1; here you suppose to use #str1
L.s=" Letters or"
Spces.s=" double spaces"
CreateRegularExpression(1, "^\d[\d ]*\d$")
Answr = MatchRegularExpression(1,GetGadgetText(#str1))
;If EventType() = #PB_EventType_Change
If answr=#True
SetGadgetColor(#txt2,#PB_Gadget_FrontColor, #Blue)
SetGadgetText(#txt2, "Correct")
Else
SetGadgetColor(#txt2,#PB_Gadget_FrontColor, #Red)
SetGadgetText(#txt2, l+Spces+" Oh no!")
EndIf
;???(EventGadget())
;EndIf
;this is what I am after
Debug Numbrs0T9wSpaces("44 766 7123 8384")
Debug Numbrs0T9wSpaces("44 766 7123 8384")
;although this is #true I dont want doubles space
Debug Numbrs0T9wSpaces(" 44 766 7123 8384")
;correct I don't want spaces in the begining
Debug Numbrs0T9wSpaces("44 766 7123 8384 ")
;also correct I don't want spaces at the end
Debug Numbrs0T9wSpaces("44 766 7123 8384c")
; correct I don't want letters
Debug Numbrs0T9wSpaces("44 766 7123 ftreh")
; " " " " "
Debug Numbrs0T9wSpaces("d44 766 7123 8384")
; " " " " "
EndSelect
EndSelect
Until appQuit