WAP 手机 输入框的格式限制

可以让用户只能输入数字、大写字母、小写字母
对于手机上的输入框的格式限制还是太简单了些。没办法。

以下来源
http://blog.mant.com.cn/?action=show&id=416
对于作者提到的输入小数的问题我打算将一个输入框分成两个处理。如果不对文本框输入内容做限制,用户输入数字时切换输入法相当麻烦。


[quote]
The -wap-input-format WCSS property takes a number of format characters as its value. The format characters specify the type and number of characters that can be entered in a text field. The -wap-input-format WCSS property should be applied to the <input type=”text”>, <input type=”password”> and <textarea> tags. There will be no effect if it is applied to other XHTML MP tags. The property value of -wap-input-format is called the input mask.

The following table shows the format characters available (format characters are case-sensitive):
Format characters Usage
a It is used to represent any lowercase letter or symbolic character.
A It is used to represent any uppercase letter or symbolic character.
n It is used to represent any numeric or symbolic character.
N It is used to represent any numeric character.
x It is used to represent any lowercase letter, numeric or symbolic character.
X It is used to represent any uppercase letter, numeric or symbolic character.
m It is used to represent any character. The WAP browser is in lowercase input mode by default but can be changed to uppercase input mode.
M It is used to represent any character. The WAP browser is in uppercase input mode by default but can be changed to lowercase input mode.



Here are two WAP CSS examples that illustrate the usage of the -wap-input-format property:

-wap-input-format: “NN”

Meaning: You must enter 2 numeric characters in a text field with this WAP CSS style rule applied.

-wap-input-format: “AAAAA”

Meaning: You must enter 5 uppercase letters or symbolic characters in a text field with this WAP CSS style rule applied.

The input mask must be enclosed in double quotes or single quotes since the -wap-input-format property takes a string value. Note that single quotes do not work in Openwave Mobile Browser 6.2.2. For example, the following markup does not work properly in Openwave Mobile Browser 6.2.2:

<input type=”text” style=”-wap-input-format: ‘N’”/>

You have to change it to the following markup so that the input mask is enclosed in double quotes:

<input type=”text” style=’-wap-input-format: “N”‘/>

It is a good practice to set an input mask for an input field, since the input mode (alphanumeric mode, numeric mode, etc) of a mobile phone’s keypad will be set automatically according to the input mask. It is a very convenient feature for the users of your mobile Internet application. For example, if the input mask is “NN” (it specifies that the text field can only accept 2 numeric characters), a mobile phone’s keypad will be set to numeric mode automatically. If you press a key of the mobile phone, no alphabets or symbols can be outputted.

You can add a single numeric character before a format character in an input mask. For example:

-wap-input-format: “2N”

It means a user can enter a maximum of 2 numeric characters in a text field. (Notice that the meaning of “2N” is different from that of “NN”.)

Also, you can add the * character before a format character in an input mask. For example:

-wap-input-format: “*N”

It means there is no limit in the number of numeric characters that can be entered.

Another example is:

-wap-input-format: “A*a”

It means the user must:

enter one uppercase character (or symbolic character), and then
enter zero or more lowercase character (or symbolic character)

The input mask “A*a” can be applied to text fields that are used to obtain a name from the user. It ensures that the first character must be in uppercase. For example, the user can only enter “Peter” but not “peter”.

The default value of the -wap-input-format WCSS property is “*M”.

The following two rules should be followed when adding a numeric character or the * character before a format character:

You can only use such character combination once in the input mask.
You can only use such character combination at the end of the input mask.

Here are some examples of invalid WCSS style rule:

-wap-input-format: “9N9N” — Reason: You can only use 9N once in the input mask.
-wap-input-format: “*Naa*N” — Reason: You can only use *N once in the input mask.
-wap-input-format: “9NNNN” — Reason: You can only use 9N at the end of the input mask. The correct format should be “NNN9N”.
-wap-input-format: “*NA” — Reason: You can only use *N at the end of the input mask.

If a value of invalid syntax is assigned to the -wap-input-format property, WAP browsers will ignore the property.

Escaped characters can be included in an input mask. To escape a character, you put two backslashes (i.e. ) in front of that character. (Note: The Openwave Mobile Browser 6.2.2 does not follow the correct WCSS language syntax. It uses a single backslash for character escaping.)

Why do we need escaped characters in the input mask? Look at this example and you will understand. Let’s say you want a user to enter a date of the form MM/DD/YYYY and you specify “NN/NN/NNNN” (or “NN/NN/NNNN” for Openwave Mobile Browser 6.2.2) as the input mask. If the user use Openwave Mobile Browser, the / character will be inserted automatically at the third and the sixth character position of the text field as he/she types the date. If the user use the Nokia Mobile Browser, the / character will not be inserted automatically but the browser will forbid the user to enter characters other than / at the third and the sixth character positions. The input mask in this example ensures that the third and sixth characters must be /.

(A note for mobile Internet application developers who are familiar with WML 1.x:

Character escaping in the -wap-input-format property value is different from that in the format attribute value of WML 1.x. Two backslashes are used to escape a character in the -wap-input-format property value while a single backslash is used for the same purpose in the format attribute value. For example, the following XHTML MP markup:

<input type=”text” style=’-wap-input-format: “bN”‘/>

is equivalent to the following WML 1.x markup:

<input type=”text” format=”bN”/>

You have to use two backslashes in WCSS because a backslash is a special character in the WCSS language. To let a backslash character to be part of a property value, it has to be escaped by another backslash. This means if you specify -wap-input-format: “bN” in the cascading style sheet, the WCSS processor will treat it as -wap-input-format: “bN”.)



我使用的结果还可以,但是只能是纯数字,不能输入小数点,纠结啊...
[/quote]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值