how to validate Textbox input ?

windows

Guest
Hi guys. I got a form that i ask the user to input data on it and it write it in sql server db. 2 of the field data i want their sum does not exceed a perticuler value for example 5 . How i can apply such bussiness rules in to my database and input form(at the client side). I be happy if some one show how to do this

<!-- m --><a class="postlink" href="http://i5.photobucket.com/albums/y180/method007/sumform.jpg">http://i5.photobucket.com/albums/y180/m ... umform.jpg</a><!-- m --> ( form pic)


insert code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim MyCommand As SqlCommand

Dim UpdateCmd As String = "Insert Into Matches Values(" & Me.TextBox1.Text & "," & Me.TextBox2.Text & "," & Me.LstPlayer.SelectedValue & "," & Me.TextBox4.Text & "," & Me.TextBox5.Text & ")"

MyCommand = New SqlCommand(UpdateCmd, MyConnection)
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
MyCommand.Connection.Close()
Server.Transfer("Match.aspx")


End SubI'd say Client side javaScripting (sorry, i don't do VB so my stuff will be in C#)

first, add an attribute to the submit button
(subButton.Attributes.Add("onclick","checkSum()"); )
then create a javaScript code
something like this: (it's not PHP, just it makes it look better ;))

function checkSum()
{
if(document.getElementById('won_id').value+document.getElementById('loss_id').value>5)
{
window.alert("Wins and losses can't equal more than 5");
}
else
{
document.Form1.submit();
}
}

Hope that helps!Look into the custom validator control.

Eric
 
Back
Top