2
I have a form from DevExtreme
and in this form I have a NumberBox
which is from a telephone field, but this field accepts only números
(obvious), .
and ,
, but the phone, it could be like (xxx)xxxxx-xxxx
accepting only hyphen, parentheses and number, but my field does not allow me to do this, my phone field is of type string
then I can change from NumberBox
for TextBox
, but with TextBox
I need to limit to accept only números, hífens e parênteses
, I know I can use the onkeypress
which calls a function in Javascript, but I don’t know how to create this function, how can I do this?
I’m not gonna post all the code 'cause it’s really big .
groupItems.AddSimpleFor(m => m.Bcx_telefone).CssClass("agTel")
.Editor(e => e.NumberBox().Width("100px").Max(9999999999).ID("agTelId"));
For now it is as shown above, but with TextBox
, gets like this:
groupItems.AddSimpleFor(m => m.Bcx_telefone).CssClass("agTel")
.Editor(e => e.TextBox().Width("100px").MaxLength(15).OnKeyPress("key_press").ID("agTelId"));
Javascript:
function key_press(e) {
//Não sei como continuar e bloquear os caracteres
}
I see that your code works running here, but in mine it doesn’t work, maybe I’m doing something wrong, but I removed Onkeypress and added Document.get... inside the <script></script>, I’m sure or should be declared outside?
– Jeff Henrique
See if it shows an error in the console?
– Sam
You’d have to start a chat so I could show you the print?
– Jeff Henrique