Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with Formating Text Box

Hello,

I am using the code below to force users to enter text in a TextBox in the following format: xx,xxx.

1. How do I modify the code, to alert the users as soon as they don't meet the format during a key press event or
when they leave the control and try to populate other fileds?

2. How do I Mask my TextBox as Follows A_B_C_D_    where _ is where they can only enter numbers? and also trigger an alert if the format is not followed?

I will need to Reterive the entire text, For example A1B2C3D4, not just the numbers they enter.

 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
            Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ErrorMessage="Invalid Format (xx,xxx)" ValidationExpression="\d{2},\d{3}" ControlToValidate="TextBox1"
            Display="Dynamic"></asp:RegularExpressionValidator>


Thanks,

Victor
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of Victor  Charles

ASKER

Hello,

I tried the following but I'm getting a compilation error message, can you please help me with the proper javascript format.

Code in Header tag:
<script type="text/javascript" id="Validate" runat =server>
function validate() {
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
            Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ErrorMessage="Invalid Format (xx,xxx)" ValidationExpression="\d{2},\d{3}" ControlToValidate="TextBox1"
            Display="Dynamic"></asp:RegularExpressionValidator>
};
</Script>


Code in Form tag:
 <asp:TextBox ID="TextBox1" runat="server" onblur = "Validate()"></asp:TextBox>



You have put asp.net validators in javascript. I thought you want to do custom validation

What should  I include in the Javascript section to enforce the format that I want using onblur?
You can use some string manipulation or regular expressions etc.

http://www.javascriptkit.com/javatutors/re.shtml
Hi,

Thaks for the link, unfortunately it didn't help sokve the issue. I have two primary goals,

1, How do I  force the users to Enter "A" (0-9) B (0-9)(0-9)C (0-9) G(0-9) For example: A1B36C8D8

2. How do I force the users to Enter  ( 4 Didits) (Dash) (Three digits)(Dash)(4Digts) For example:
1206-00-027-3767

Victor
I think your best bet is to use a Masked Textbox.
I don't see it in my ToolBox, does it come with VS2010 professional version?
i AM TRYING TO INSTALL THE ajax EXTENSION BUT SO FAR NO LUCK, ANY HELP FROM YOU WOULD BE GREATLY APPRECIATED.
Download the correct version for your .NET framework, install it, then reference the DLLs. Which step are you stuck at?
I installed the Ajax extension library, but I don't see it in my toolbox or can't see in the section where I can choos the controls.
Hi again,

Does the Masked edit box have a datasource property? I need to bound it to a data source to view the data in my xml files.
The maskededitbox itself wont have a datasource. Datasource will be set on the container (repeater, grid etc) level and then you can add databindings on the textbox level.
I can set the datasource to a Grid, can you please send me an example on how to use databindings on the textbox level. I will load my combobox with multiple records but will remove thre trigger for users no to see all the data at once, they will need to click the Nex/Previous buttons to move through the records, I wanted to use a combobox, but I can't format it to force users to enter data in a certain format.
I can set the datasource to a Grid, can you please send me an example on how to use databindings on the textbox level. I will load my combobox with multiple records but will remove thre trigger for users no to see all the data at once, they will need to click the Nex/Previous buttons to move through the records, I wanted to use a combobox, but I can't format it to force users to enter data in a certain format.
Use the Text property of the maskedtextbox.
Hi,

I used the following code, but nothing appears in the textbox:

 Repeater1.DataSource = dtDonor
  ' Repeater1.DataMember = "Countryorigin"
 C1Manufacturer.Text = Repeater1.DataSource

How do you properly connect the Textbox control with the repeater datasource?
Correction with code:
 Repeater1.DataSource = dtDonor
Repeater1.DataMember = "Countryorigin"
Repeater1.Databind()
C1Manufacturer.Text = Repeater1.DataSource
Hi,

I tried to follow the example by using the code below, but the C1manufacturer Textbox control still doesn't display the data. Can you please help me come up with the proper code.

ASPX File:

 <asp:Repeater ID="RepeatControl" runat="server">
                    <ItemTemplate>
                    DataBinder.Eval(Container.DataItem,"CountryOrigin_ID")
                    C1manufacturer.Text="<%#DataBinder.Eval(Container.DataItem, "CountryOrigin")%>"  
                    </ItemTemplate>
                    </asp:Repeater>

Vb File Search Button:

 RepeatControl.DataSource = dtDonor
        RepeatControl.DataBind()
My goodness. Try

 <asp:Repeater ID="RepeatControl" runat="server">
                    <ItemTemplate>
                    <asp:Textbox id="C1manufacturer" Text="<%#DataBinder.Eval(Container.DataItem, "CountryOrigin")%>"  />
                    </ItemTemplate>
                    </asp:Repeater>

I tried your code but still no data in my Textbox control, below is my code and also in part B, the code for dsiplaying the data in a combobox.

<asp:Repeater ID="RepeatControl" runat="server">
                    <ItemTemplate>
                    <asp:Textbox id="C1manufacturer" Text="<%#DataBinder.Eval(Container.DataItem, "CountryOrigin")%>"/>
                    </ItemTemplate>
                    </asp:Repeater>

Button Click event:

RepeatControl.DataSource = dtDonor
        RepeatControl.DataBind()
*****************************888
Part B:
        C1FuzeA.DataSource = dtDonor
        C1FuzeA.DataTextField = "CountryOrigin"
        C1FuzeA.DataValueField = "CountryOrigin_ID"
        C1FuzeA.DataBind()
You need to set the datasource of the repeater similar to what you did for drop down.
Not sure what you mean, The Repeater Control.DataSource is set to DtDonor , similar to the Combobox, but it doesn't have a datatextField or dataValuefield property.
Oh yeah I missed that. I am at a loss now. Do you have teamviewer?
I don't have teamviewer.
ASKER CERTIFIED SOLUTION
Avatar of jagssidurala
jagssidurala
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you , will test your code and get backup you.
Thanks You!