Ola gente eu estou com um problema ao validar o telefone nesse campo quando eu uso o seguinte javaScript:
[code]function TelefoneFormat(Campo, e) {
var key = ‘’;
var len = 0;
var strCheck = ‘0123456789’;
var aux = ‘’;
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13 || whichCode == 8 || whichCode == 0)
{
return true; // Enter backspace ou FN qualquer um que não seja alfa numerico
}
key = String.fromCharCode(whichCode);
if (strCheck.indexOf(key) == -1){
return false; //NÃO E VALIDO
}
aux = Telefone_Remove_Format(Campo.value);
len = aux.length;
if(len>=8)
{
return false; //impede de digitar um telefone maior que 10
}
aux += key;
Campo.value = Telefone_Mont_Format(aux);
return false;
}
function Telefone_Mont_Format(Telefone)
{
var aux = len = ‘’;
len = Telefone.length;
if(len<=9)
{
tmp = 4;
}
else
{
tmp = 6;
}
aux = '';
for(i = 0; i < len; i++)
{
aux += Telefone.charAt(i);
if(i+1==tmp)
{
aux += '-';
}
}
return aux ;
}
function Telefone_Remove_Format(Telefone)
{
var strCheck = ‘0123456789’;
var len = i = aux = ‘’;
len = Telefone.length;
for(i = 0; i < len; i++)
{
if (strCheck.indexOf(Telefone.charAt(i))!=-1)
{
aux += Telefone.charAt(i);
}
}
return aux;
}[/code] e coloco nesse campo:
Ele formata o telefone no formato que quero 2222-2222 so que ele nao vai pro banco, como é que eu faço pro campo que ta retornando no javaScript va para o banco nesse bean que eu tenho??
@Entity @NamedQueries(
{ @NamedQuery(name = “Funcionario.recuperarPorNome”, query = “SELECT f FROM Funcionario f WHERE f.nome = :nome”), @NamedQuery(name = “Funcionario.recuperarPorId”, query = “SELECT f FROM Funcionario f WHERE f.id = :id”), @NamedQuery(name = “Funcionario.recuperarFuncionarioLikeNome”, query = “SELECT f FROM Funcionario f WHERE f.nome LIKE :nome”), @NamedQuery(name = “Funcionario.recuperarTodos”, query = “SELECT f FROM Funcionario f ORDER BY f.nome”)
})
public class Funcionario implements Serializable {
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
private Long id;
@Column
private String nome, email, dataNasc, telefone;
public Funcionario() {
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (this.getId() != null ? this.getId().hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Funcionario)) {
return false;
}
Funcionario other = (Funcionario)object;
if (this.getId() != other.getId() && (this.getId() == null || !this.getId().equals(other.getId()))) return false;
return true; }
@Override
public String toString() {
return "entity.Funcionario[id=" + getId() + "]";
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDataNasc() {
return dataNasc;
}
public void setDataNasc(String dataNasc) {
this.dataNasc = dataNasc;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}