[英]How to validate values entered in the TEdit and how to restrict TMaskEdit to allow only numbers?
I need help with doing validation for certain controls. 我需要对某些控件进行验证的帮助。
Question 1: 问题1:
I have a TEdit control on my form. 我的表单上有一个TEdit控件。 I would like to check whether the data entered by the user is either an alphabet or a number.
我想检查用户输入的数据是字母还是数字。
Question 2: 问题2:
I have a TMaskEdit control on my form and I want to restrict users to enter only numbers. 我的表单上有一个TMaskEdit控件,我想限制用户只能输入数字。
Can anybody post code samples how to do that ? 有人可以邮寄示例代码吗?
Any help is appreciated. 任何帮助表示赞赏。
I have a TEdit control in my form.
我的表单中有一个TEdit控件。 I would like to check whether the data entering by the user is either an alphabet or a number.
我想检查用户输入的数据是字母还是数字。
Look at the TryStrToInt()
function in the SysUtils unit. 查看
TryStrToInt()
单元中的TryStrToInt()
函数。 If it returns True, the text is a valid number. 如果返回True,则文本为有效数字。
I have a TMaskEdit control in my form .
我的表单中有一个TMaskEdit控件。 and I want the user to enter only numbers.
我希望用户仅输入数字。
Read the documentation on how the TMaskEdit.EditMask
property works. 阅读有关
TMaskEdit.EditMask
属性如何工作的文档。 Set the mask to contain as many '#'
characters as you want to allow users to enter digits. 设置掩码,使其包含尽可能多的
'#'
字符,以允许用户输入数字。
Altrnatively, switch to TEdit
and use the SetWindowsLong()
function to give it the ES_NUMBER
style. 另外,切换到
TEdit
并使用SetWindowsLong()
函数为其赋予ES_NUMBER
样式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.