Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Validators

  1. #1

    Controlli

    Sono disperata ho una form con i seguenti campi
    -Telefono fisso
    -Telefono Cellulare
    -Data
    -Email
    e altri
    devo fare un'inserimento e devo controllare che questi campi diano scritti in maniera corretta, ossia il telfisso (es.06/52222),telcel(es.325/14454),data(es.15/05/2003),email(dsf@ere.it), come faccio.Premetto che ho provato ad usare i validator di asp.net ma è un bordello. Grazie

  2. #2
    Utente bannato
    Registrato dal
    Jan 2002
    Messaggi
    233
    <asp:regularexpressionvalidator runat="server" ControlToValidate="tel" ValidationExpression="(^(\d{3}.\d{6})$)|(^(\d{3}.\ d{7})$)|(^(\d{4}.\d{6})$)|(^(\d{4}.\d{7})$)" ErrorMessage="il numero telefonico non è corretto" Display="None"/>
    questo x il telefono(x cell bastano poche modifiche)

    <asp:regularexpressionvalidator runat="server" ControlToValidate="email" ValidationExpression="(\w+\.\w+\@\w+\.\w+)|(\w+\@\ w+\.\w+)" ErrorMessage="Devi inserire un'e-mail valida" Display="None"/>

    e questo x l'email.
    x la data utilizza un compare validator con la proprietà type="date"

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    10
    <asp:RegularExpressionValidator Runat="server"
    ControlToValidate="tel1"
    ValidationExpression="[0-9]{10}"
    ErrorMessage="Controlla il Numero di Telefono!!!"/>

    Puoi modificare la ValidationExpression come ha detto giannola!!!


    <asp:RegularExpressionValidator Runat="server"
    ControlToValidate="mail1"
    ValidationExpression="\w+\@\w+\.\w+"
    ErrorMessage="Controlla l'E-Mail!!!"/>

    Se l'estensione mail (.com, .net, .it) dovesse essere fissa basta cambiare l'ultima w+ con com o net o it ecc.

    Ciao Ciao Fude

  4. #4

    Poi?

    Una volta scritti nell'html così come faccio a controllarli, nel senso ho un bottone per l'inserimento e non voglio che l'utente inserisca i dati se qualcuno è sbagliato come li controllo?

  5. #5

    Dimenticavo

    Per quanto riguarda la data ho usato quello che hai scritto te ma se prova ad inserire una data dopo quellz attuale mi da errore come faccio

  6. #6
    con i validator non vai avanti finche tutte le condizioni che tu hai messo non vengono soddisfatte.


    poi nella funzione che hai associato al bottone fai un controllo cosi:
    if Page.IsValid then
    'fai quello ceh ti pare
    else
    'errore
    end if

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    10
    Ti faccio vedere una mia form molto semplificata, prova a vedere se c'è qualcosa che ti può essere utile...

    <%@ Language="VB" Debug="true" Culture="it-IT" %>
    <script runat="server">
    'sub Submit(obj as object, e as eventargs)
    'if Page.IsValid then
    'insert.Text = "Corretto"
    'else
    'insert.Text = "Uno dei Campi non e' Corretto"
    'end if
    'end sub
    sub invia(obj as object, e as eventargs)
    insert.text=" ECCO I DATI RICEVUTI :
    "
    insert.text=insert.text & nome.text & nome1.text & "
    "
    insert.text=insert.text & cognome.text & cognome1.text & "
    "
    insert.text=insert.text & data.text & data1.text & "
    "
    insert.text=insert.text & via.text & via1.text & "
    "
    insert.text=insert.text & civico.text & civico1.text & "
    "
    insert.text=insert.text & cap.text & cap1.text & "
    "
    insert.text=insert.text & citta.text & citta1.text & "
    "
    insert.text=insert.text & prov.text & prov1.text & "
    "
    insert.text=insert.text & paese.text & paese1.selectedItem.text & "
    "
    insert.text=insert.text & tel.text & tel1.text & "
    "
    insert.text=insert.text & telefono.text & telefono1.text & "
    "
    insert.text=insert.text & mail.text & mail1.text & "
    "
    dim check as string
    if checkbox.checked then
    check="SI"
    else
    check="NO"
    end if
    insert.text=insert.text & iscrizione.text & check & "
    "
    insert.text=insert.text & identificatore.text & identificatore1.text & "
    "
    end sub
    </script>
    <html>
    <head>
    <meta name="GENERATOR" Content="Microsoft Visual Studio.NET 7.0">
    </head>
    <body bgColor="#6699ff" runat="server">
    <form runat="server">
    <center>
    <asp:Label id="insert" text="INSERIMENTO DATI" font-size="18" runat="server"></asp:Label>




    <asp:Panel id="Panel" runat="server">
    <table id="tabella" runat="server">
    <tr>
    <td>
    <asp:Label id="nome" text="Nome*:" runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox id="nome1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="nome1"
    ErrorMessage="Inserisci il NOME!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="cognome" text="Cognome*:" runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox id="cognome1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="cognome1"
    ErrorMessage="Inserisci il COGNOME!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="data" text="Data Nascita*:" runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox id="data1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="data1"
    ErrorMessage="Inserisci la DATA DI NASCITA!!!"/>
    <asp:CompareValidator Operator="DataTypeCheck" Type="date"
    ControlToValidate="data1"
    ErrorMessage="Inserisci la data corretta!!!" runat="server"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="via" text="Via*:" runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox id="via1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="via1"
    ErrorMessage="Inserisci La VIA!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="civico" text="N° Civico*:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="civico1" Runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="civico1"
    ErrorMessage="Inserisci il N° CIVICO!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="cap" text="C.A.P.*:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="cap1" Runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="cap1"
    ErrorMessage="Inserisci il C.A.P.!!!"/>
    <asp:RegularExpressionValidator Runat="server"
    ControlToValidate="cap1"
    ValidationExpression="[0-9]{5}"
    ErrorMessage="Controlla il C.A.P.!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="citta" text="Città*:" runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox id="citta1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="citta1"
    ErrorMessage="Inserisci la CITTA'!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="prov" text="Provincia(sigla)*:" runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox id="prov1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="prov1"
    ErrorMessage="Inserisci la PROVINCIA!!!"/>
    <asp:RegularExpressionValidator Runat="server"
    ControlToValidate="prov1"
    ValidationExpression="[A-Z|a-z]{2}"
    ErrorMessage="Controlla la Provincia!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="paese" text="Paese*:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:ListBox id="paese1" runat="server" size="1" width="155">
    <asp:ListItem></asp:ListItem>
    <asp:ListItem> Australia </asp:ListItem>
    <asp:ListItem> Austria </asp:ListItem>
    <asp:ListItem> Belgio </asp:ListItem>
    <asp:ListItem> Canada </asp:ListItem>
    <asp:ListItem> Finlandia </asp:ListItem>
    <asp:ListItem> Francia </asp:ListItem>
    <asp:ListItem> Germania </asp:ListItem>
    <asp:ListItem> Giappone </asp:ListItem>
    <asp:ListItem> Inghilterra </asp:ListItem>
    <asp:ListItem> Irlanda </asp:ListItem>
    <asp:ListItem> Islanda </asp:ListItem>
    <asp:ListItem> Italia </asp:ListItem>
    <asp:ListItem> Lussemburgo </asp:ListItem>
    <asp:ListItem> Norvegia </asp:ListItem>
    <asp:ListItem> Olanda </asp:ListItem>
    <asp:ListItem> Portogallo </asp:ListItem>
    <asp:ListItem> Spagna </asp:ListItem>
    <asp:ListItem> Svezia </asp:ListItem>
    <asp:ListItem> Svizzera </asp:ListItem>
    <asp:ListItem> U.S.A. </asp:ListItem>
    </asp:ListBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="paese1"
    ErrorMessage="Inserisci il PAESE!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="tel" text="Telefono Principale:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="tel1" Runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator Runat="server"
    ControlToValidate="tel1"
    ValidationExpression="[0-9]{10}"
    ErrorMessage="Controlla il Numero di Telefono!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="telefono" text="Telefono Secondario:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="telefono1" Runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator Runat="server"
    ControlToValidate="telefono1"
    ValidationExpression="[0-9]{10}"
    ErrorMessage="Controlla il Numero di Telefono!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="mail" text="E-Mail*:" runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox id="mail1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="mail1"
    ErrorMessage="Inserisci l'E-MAIL!!!"/>
    <asp:RegularExpressionValidator Runat="server"
    ControlToValidate="mail1"
    ValidationExpression="\w+\@\w+\.\w+"
    ErrorMessage="Controlla l'E-Mail!!!"/>
    </td>
    </tr>
    <tr>
    <td>

    <asp:Label ID="iscrizione" Text="Iscrizione alla Mailing List:" Runat="server"></asp:Label>
    </td>
    <td>

    <asp:CheckBox ID="checkbox" value="vero" Runat="server"></asp:CheckBox>
    </td>
    </tr>
    <tr>
    <td>


    <asp:Label id="identificatore" text="ID*:" Runat="server"></asp:Label>
    </td>
    <td>


    <asp:TextBox ID="identificatore1" Runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="identificatore1"
    ErrorMessage="Inserisci l'ID!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="pass" text="Password*:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="pass1" TextMode="Password" Runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="pass1"
    ErrorMessage="Inserisci la PASSWORD!!!"/>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="repass" text="Riscrivi la Password*:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="repass1" TextMode="Password" Runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator Runat="server"
    ControlToValidate="repass1"
    ErrorMessage="Inserisci la PASSWORD!!!"/>
    <asp:CompareValidator Runat="server"
    ControlToValidate="repass1"
    ControlToCompare="pass1"
    Type="String"
    Operator="Equal"
    ErrorMessage="Le PASSWORD non corrispondono!!!"/>
    </td>
    </tr>
    </Table>


    ATTENZIONE: I CAMPI CONTRASSEGNATI DA * SONO OBBLIGATORI!!!






    I Tuoi Interessi:
    <Table>
    <tr>
    <td>

    <asp:Label id="cine" text="Cinema:" Runat="server"></asp:Label>
    </td>
    <td width="100">

    <asp:CheckBox id="cine1" runat="server"/></asp:CheckBox>
    </td>
    <td>

    <asp:Label id="teatro" text="Teatro:" Runat="server"></asp:Label>
    </td>
    <td width="100">

    <asp:CheckBox id="teatro1" runat="server"/></asp:CheckBox>
    </td>
    <td>

    <asp:Label id="manif" text="Manifestazioni:" Runat="server"></asp:Label>
    </td>
    <td>

    <asp:CheckBox id="manif1" runat="server"/></asp:CheckBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="musica" text="Musica:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="musica1" runat="server"/></asp:CheckBox>
    </td>
    <td width="100">
    <asp:Label id="concerti" text="Concerti:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="concerti1" runat="server"/></asp:CheckBox>
    </td>
    <td>
    <asp:Label id="spettacoli" text="Spettacoli:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="spettacoli1" runat="server"/></asp:CheckBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="shopping" text="Shopping:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="shopping1" runat="server"/></asp:CheckBox>
    </td>
    <td width="100">
    <asp:Label id="abbigliamento" text="Abbigliamento:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="abbigliamento1" runat="server"/></asp:CheckBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="salute" text="Salute:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="salute1" runat="server"/></asp:CheckBox>
    </td>
    <td>
    <asp:Label id="fitness" text="Fitness:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="fitness1" runat="server"/></asp:CheckBox>
    </td>
    <td>
    <asp:Label id="terme" text="Terme:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="terme1" runat="server"/></asp:CheckBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="sport" text="Sport:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="sport1" runat="server"/></asp:CheckBox>
    </td>
    <td>
    <asp:Label id="attrezzature" text="Attrezzature:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="attrezzature1" runat="server"/></asp:CheckBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label id="tecno" text="Tecnologia:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="tecno1" runat="server"/></asp:CheckBox>
    </td>
    <td>
    <asp:Label id="comp" text="Computer:" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:CheckBox id="comp1" runat="server"/></asp:CheckBox>
    </td>
    </tr>
    </table>
    <center>
    <asp:Label id="altro" text="Altro (specificare):" runat="server"></asp:Label>
    <asp:TextBox id="altro1" runat="server"></asp:TextBox>
    </center>


    <center>
    <asp:Button id="Button" OnClick="Invia" Text="Avanti" Runat="server"/>
    </center>
    </asp:Panel>
    </center>
    </form>
    </body>
    </html>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.