Solved

Help with testing format of data entered before saving data in an XML file.

Posted on 2011-09-29
4
202 Views
Last Modified: 2012-05-12
Hello,

What is the VB.NET syntax to check the format of a text before it saves the data to an XML file?

Dim MyReceiver As XDocument = XDocument.Load(Server.MapPath("~/App_Data/Receiver.xml"))
Dim LargestReceiverID = (From el In MyReceiver.Descendants("ReceiverTable") Select CInt(el.<Receiver_ID>.Value)).ToList
        LargestReceiverID.Sort()
        Dim CheckForItemB = (From el In MyReceiver.Descendants("ReceiverTable").Elements("Receiver") Select el.Value).ToList
         If Not CheckForItemB.Contains(Me.TextBox1.Text.ToString) Then
          *****If format of Textbox1.text is "9999-99-999-9999" (syntax?) then*******
           Dim xNew As XElement = New XElement("ReceiverTable")
            xNew.Add(New XElement("Receiver_ID", (LargestReceiverID.Last() + 1)))
            xNew.Add(New XElement("Receiver", Me.TextBox1.Text.ToString))
            MyReceiver.Root.Add(xNew)
            MyReceiver.Save(Server.MapPath("~/App_Data/Receiver.xml"))
        End If
       End if


Thanks,

Victor
0
Comment
Question by:vcharles
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 36891189
Use an regular expression to check.  BTW, you can also enforce the format on the page by a RegularExpressionValidator.
' from System.Text.RegularExpressions
    Dim rx As New Regex("\d{4}-\d{2}-\d{3}-\d{4}")
    If rx.IsMatch(TextBox1.Text) Then
      'place code here to do when in correct format
    End If

Open in new window

0
 

Author Comment

by:vcharles
ID: 36891216
Hello,

Is there to execute the code while the user it typing the data in the Textbox and if there is no match to prompt him/her of the required format? How do you use the RegularExpressionValidator, I have to do this for many controls, textboxes, comboboxes, perhaps it would be best to use the RegularExpression Validator.

Thanks,

Victor
0
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 500 total points
ID: 36891338
The link is an overview of the validation controls.  Basically, the standard validation controls within a validation group are triggered on the client side by control with the causevalidation property set to true (usually a button).  A validation group is a similiar concept to a radio button group.  I use them extensively for user input for dates, numbers, and formatted data such as SSAN, telephone numbers, etc.  

http://msdn.microsoft.com/en-us/library/aa479013.aspx

To restrict what the user enters as they type, you may want to check out the MaskedEdit ASP.NET AJAX extender.  
http://www.asp.net/ajaxlibrary/act_MaskedEdit.ashx

Both controls have the concept to restrict the data format on the client side before it is sent to the server.  Of course, there is always an exception.  The customvalidator can be set up to be sent to the server, then the Page.IsValid property must be checked.  Also, JQuery can be used, but I do not have any specific knowledge on it.

Depending on your need, the validation controls handles most data entries.  I would use these before using the other options.

0
 

Author Closing Comment

by:vcharles
ID: 36891379
Thank You!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Web site error 3 36
Gridview alignment 1 19
transaction in asp.net, sql server 6 31
asp.net mvc5 6 12
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now