mIRC Home    About    Download    Register    News    Help

Print Thread
#43824 23/08/03 10:40 PM
A
avataru
avataru
A
i have this code:
Code:
 
dialog npl_make_sid {
  title "Current Session ID (sid)"
  size -1 -1 109 37
  option dbu

  edit "", 1, 3 2 102 10, autohs result
  text "eg. 172601fec2fc54ae04802f39e3f3603b", 2, 4 13 130 8
  button "Ok", 3, 3 24 37 10, ok
  button "Skip", 4, 68 24 37 10, cancel
}

alias nplist.sid {
  var %npl_temp = $dialog(npl_make_sid,npl_make_sid)
  return %npl_temp
}

on *:dialog:npl_make_sid:*:* {
  if ($devent == init) did -b $dname 3
  if ($devent == edit) { 
    if ($did == 1) {
      did -e $dname 3
      if (!$regex($did(1),[0-9a-z]$)) did -j $dname 1 
    }
  }
}


when i do let's say //echo -a $nplist.sid and try to enter invalid chars (caps, misc chars not 0-9 or a-z) they appear in the editbox and they shouldn't because of the -j.

why is that?

what i want to happen when invalid chars are entered is:
a. if the string is copied from somewhere and pasted in the editbox, the editbox should remain empty
b. if the characters are entered one by one, when an invalid char is entered it should be deleted

thanks in advance

ps: i know that the regex won't work for case "a" because it only checks the last char and i would appreciate if someone could correct it.

#43825 23/08/03 11:04 PM
Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
Actually /did -j does not undo whatever you have typed in the editbox. All it does is reset $did().edited to $false. Open up your dialog, type something in the editbox and then type
//echo -a $did(npl_make_sid,1).edited
you get $true
now type:
//did -j npl_make_sid 1 | echo -a $did(npl_make_sid,1).edited
you get $false

As for the actual problem, I've written an alias that makes editboxes accept only numbers (digits). Here it is:
Code:
[color:green]; /numbersonly <dialog name> <id of editbox> [max number][/color]
alias numbersonly {
  var %a = $did($1,$2), %s = $did($1,$2,1).selstart
  if $mid(%a,%s,1) !isnum { did -ra $1-2 $remove(%a,$ifmatch) | did -c $1-2 1 %s }
  if $did($1,$2) > $3 { did -ra $1-3 | did -c $1-2 1 -1 }
}
You can then use it in your edit event, like this:
Code:
on *:dialog:npl_make_sid:edit:1: numbersonly $dname $did 1000
This would make the editbox accept only digits and only when the number is smaller or equal to 1000. If you don't want an upper limit, just omit 1000.


Link Copied to Clipboard