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
vcharlesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
0
vcharlesAuthor Commented:
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>



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

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

http://www.javascriptkit.com/javatutors/re.shtml
0
vcharlesAuthor Commented:
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
0
CodeCruiserCommented:
I think your best bet is to use a Masked Textbox.
0
vcharlesAuthor Commented:
I don't see it in my ToolBox, does it come with VS2010 professional version?
0
vcharlesAuthor Commented:
i AM TRYING TO INSTALL THE ajax EXTENSION BUT SO FAR NO LUCK, ANY HELP FROM YOU WOULD BE GREATLY APPRECIATED.
0
CodeCruiserCommented:
Download the correct version for your .NET framework, install it, then reference the DLLs. Which step are you stuck at?
0
vcharlesAuthor Commented:
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.
0
vcharlesAuthor Commented:
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.
0
CodeCruiserCommented:
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.
0
vcharlesAuthor Commented:
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.
0
vcharlesAuthor Commented:
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.
0
CodeCruiserCommented:
Use the Text property of the maskedtextbox.
0
vcharlesAuthor Commented:
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?
0
vcharlesAuthor Commented:
Correction with code:
 Repeater1.DataSource = dtDonor
Repeater1.DataMember = "Countryorigin"
Repeater1.Databind()
C1Manufacturer.Text = Repeater1.DataSource
0
CodeCruiserCommented:
0
vcharlesAuthor Commented:
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()
0
CodeCruiserCommented:
My goodness. Try

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

0
vcharlesAuthor Commented:
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()
0
CodeCruiserCommented:
You need to set the datasource of the repeater similar to what you did for drop down.
0
vcharlesAuthor Commented:
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.
0
CodeCruiserCommented:
Oh yeah I missed that. I am at a loss now. Do you have teamviewer?
0
vcharlesAuthor Commented:
I don't have teamviewer.
0
jagssiduralaCommented:
For your req you need to write a script and assign the same to custom validator.

function fncvalidate(Src,Args)
{
  var strText = document.getElementById('yourtextboxid'
 
  if(strText.length == 8 && str.substring(0,1) == 'A' && parseInt(str.substring(1,2)) > 0 && str.substring(2,3) == 'B' && parseInt(str.substring(3,4)) > 0 && str.substring(4,5) == 'C' && 
parseInt(str.substring(5,6)) > 0 && str.substring(6,7) == 'D' && parseInt(str.substring(7,8)) > 0)
{
 Args.IsValid = true;
}
else
{
Args.IsValid = false;
}

}

assign this function as clientvalidatefunction to the customvalidator which will validate the textbox value.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vcharlesAuthor Commented:
Thank you , will test your code and get backup you.
0
vcharlesAuthor Commented:
Thanks You!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.