找回密码
 加入
搜索
楼主: touch_xu

[AU3基础] 【已解决】Input 如何只能输入正数,可以是小数

 火... [复制链接]
发表于 2011-9-21 09:13:11 | 显示全部楼层
楼主几位的正则和方法有时间 学习一下!
 楼主| 发表于 2011-9-21 20:44:40 | 显示全部楼层
3mile 发表于 2011-9-20 23:33



    太感谢了,这个一次就满足了我所有的请求,我认为已经完美了,当然同时感谢所以朋友的的热情帮助,向你们学习,您辛苦了。
发表于 2011-9-21 20:49:54 | 显示全部楼层
回复 17# touch_xu


    输入 0.1 试试~
发表于 2011-9-21 23:31:13 | 显示全部楼层
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 629, 106, 192, 132)
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 433, 24)
$Button1 = GUICtrlCreateButton("Button1", 496, 32, 105, 33)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1                        
                        GUICtrlSetData($Input1, '')
        EndSwitch
WEnd

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        Local Const $EN_CHANGE = 0x300
        Local $nNotifyCode = BitShift($wParam, 16)
        Local $nID = BitAND($wParam, 0xFFFF)
        Local $hCtrl = $lParam
        If $nID = $Input1 Then
                If $nNotifyCode = $EN_CHANGE Then
                        $read=GUICtrlRead($Input1)
                        If  String(StringLeft($read,2))=="00" Then
                                GUICtrlSetData($Input1,StringRegExpReplace($read,'^0+',''))
                        ElseIf  String(StringLeft($read,1))=="." Then
                                GUICtrlSetData($Input1,StringRegExpReplace($read,'(^\.)+','0.'))
                        Else
                                $write=StringRegExpReplace($read,'[^\.0-9]+','')
                                $temp=StringSplit($write,".",1+2)
                                if UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
                                GUICtrlSetData($Input1,$write)
                        EndIf
                EndIf
        EndIf
EndFunc
 楼主| 发表于 2011-9-22 22:47:47 | 显示全部楼层
回复 18# afan


    首字母0是不接受啊,所以不输入不了啊
发表于 2011-9-22 22:50:24 | 显示全部楼层
回复  afan


    首字母0是不接受啊,所以不输入不了啊
touch_xu 发表于 2011-9-22 22:47



    01 不合法,0.1 不合法吗?
3mile 已经修改了
 楼主| 发表于 2011-9-22 23:32:26 | 显示全部楼层
回复 21# afan


    可能我用的就是最后改过的吧,现在是可以了,十分感谢您的帮助,再次谢谢了。
发表于 2011-9-28 20:08:44 | 显示全部楼层
#19楼3mile的好像可以输入这样的数:01.2
发表于 2012-8-31 01:21:41 | 显示全部楼层
回复 10# afan

測試過 好像我覺得 老大的 正則 看起來好像判斷比較沒問題呢??

我試著改一下  變成

StringRegExp(GUICtrlRead($Input), '^[1-9,-]\d*(?:\.\d+)?$|^0\.\d+$|^0$')
因為我想讓 系統也可以輸入 負數 但是這樣就會出現一個 不合理的現象

-001 是可以通過的......不知道應該如何改寫 才會變成 不通過呢??
发表于 2012-8-31 08:29:43 | 显示全部楼层
回复 24# kk_lee69


    试试 StringRegExp(GUICtrlRead($Input), '^-?[1-9]\d*(?:\.\d+)?$|^-?0\.\d+$|^0$')
发表于 2012-8-31 09:41:48 | 显示全部楼层
回复 25# afan

可以了 感謝幫忙!!
发表于 2012-12-3 10:43:01 | 显示全部楼层
正则....用法很多,,,,牛人..
发表于 2012-12-3 10:43:07 | 显示全部楼层
正则....用法很多,,,,牛人..
发表于 2015-1-23 11:17:54 | 显示全部楼层
这个帖子真是经典。收藏下。
挖坟不违规吧……
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-16 16:04 , Processed in 0.072352 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表