需要帮助:根据DropDown选择的值格式的电话格式 [英] Need Help: Phone format according to DropDown selected value

查看:62
本文介绍了需要帮助:根据DropDown选择的值格式的电话格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个Dropdown和一个文本框。当用户从下拉菜单中选择电话,传真,短信时,文本框应为自动电话格式。



即用户只能输入号码,电话格式应该是如(999)99 - 9999.此验证取决于下拉值。











目前我正在使用以下javascript功能单个文本框



Hi,

I have a Dropdown and a Textbox. When the user selectes Phone, Fax, SMS from drop down , the textbox should be in auto phone format.

i.e the user can enter only number and the phone format should be like (999) 99 - 9999. This validation depends on the dropdown value.





Presently I am using the following javascript funtion for individual textboxes

function FormatedPhone(e) {
                
                    evt = e || window.event;
                    var keyPressed = evt.which || evt.keyCode;
                    
                    if (((keyPressed >= 97) && (keyPressed <= 122)) || ((keyPressed >= 65) && (keyPressed <= 90)) || (keyPressed == 59)) {
                        return false;
                    }
                    else {
                        if (keyPressed == 8 || keyPressed == 37) {
                            return;
                        }

                        var target = evt.target || evt.srcElement;

                        phone = target.value;
                        if (phone.length == 1 && phone != "(") {
                            target.value = "(" + phone;
                        }
                        else if (phone.length == 4 && phone.substring(0, 1) == "(" && !isNaN(phone.substring(1, 4))) {
                            target.value = phone + ") ";
                        }
                        else if (phone.length == 9 && phone.substring(0, 1) == "(" && !isNaN(phone.substring(1, 4)) && phone.substring(4, 5) == ")" && !isNaN(phone.substring(6, 9))) {
                            target.value = phone + "-";
                        }
                    }
                }





我在.cs Page load中调用这个javascript函数添加属性





and I am calling this javascript funtion in .cs Page load by adding the attributes

txtPhone1.Attributes.Add("Onkeypress", "return FormatedPhone(event)");







请任何人帮我根据我的要求格式化javascript功能(accroding降价值)







谢谢,



Nag




Please any body help me to format the javascript funtion according to my requirement ( accroding to dropdown value)



Thanks,

Nag

推荐答案

你要找的是一个蒙面输入。

这个 [ ^ ] javascript库帮助了我st并且为此目的看起来相当稳固。



如果您有一个下拉列表指定的多种不同格式,那么需要将其应用于文本输入,那么您''只需动态更改掩码并重新验证文本内容。
What you are looking for is a masked input.
This[^] javascript library has helped me in the past and seems reasonably solid for that purpose.

If you have multiple different formats specified by a dropdown that then need to be applied to a text input, then you''ll just have to change the mask on the fly and re-validate the textual content.


这篇关于需要帮助:根据DropDown选择的值格式的电话格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆