This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Enforcing Input

Old posts that have not been replied to for several years.
Locked
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Enforcing Input

Post by BiLL »

Hi,

I am searching for a special code to enforce users to a determined input style. But I don't know how do it in a good way.
I will explain it in a short way + example:

I have a variable $var. And I have a !input bind which sets that $var.

Example: !input test1 (sets $var = test1)
Example: !input blabla (sets $var = blabla)

But now I want to enforce the user to input a var like:
0.0x
0.5x
1.0x
1.5x
etc.
-> number.numberx <- Main Code

How can I check that Input now in a good technical way?
Please help!

Another help needed:

I got Input and $var again.
But now I want to enforce the user to an input like:
10DeCS
15DeCS
20DeCS
100DeCS
1000DeCS
etc.
-> numberDeCS <- Main Code

can anyone help me please?

Big thanks.
L
L-n

Regular Expressions

Post by L-n »

Hi,
You would enforce inputs using regular expressions. First, heres the simple tcl i used to test it, just so u know how to implement it.

bind pub - !input pubinput
proc pubinput {nick host hand chan arg} {
if {<<<INSERT REGEXP FUNCTION>>>} {
set var [lindex $arg 0]
putserv "PRIVMSG $chan :true, $var"
} else {
putserv "PRIVMSG $chan :false"
}
}

Ok, i wasnt quite sure if u wanted the 1.1x one to match a single digit, or to allow multiple, so i did both:
[regexp "^(\[0-9\])+.(\[0-9\])+x" [lindex $arg 0]]
This would match <anynumber>.<anynumber>x
e.g. 100.100x

[regexp "^\[0-9\].\[0-9\]x" [lindex $arg 0]]
This would match <singlenumber>.<singlenumber>x
e.g. 1.1x


And this is for your second example:
[regexp "^(\[0-9\])+DeCS" [lindex $arg 0]]
This would match <anynumber>DeCS
e.g. 100DeCS

For more information on regular expressions, check out:
http://www.tcl.tk/man/tcl8.3/TclCmd/re_syntax.htm
Remeber though, the slashes (\) arent part of the regular expression, they simply stop the tcl from trying to evaluate the stuff inside the square brackets ([ and ]).

Regards,
Paul
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Post by BiLL »

Exactly what I needed, BIG THANKS. You really helped me alot!!!!!
Locked