c# - Field Validation For An IP Address -
I am trying to prevent a user from distinguishing a number or a period of C # in a particular textbox . There should be an IP address in the text box. I have to do this work that non-numerical entries are being stopped, though I feel that no period of time can be allowed to enter. How can I complete it?
Private Zero TargetIP_KeyDown (Object Sender, KeyEventArgs E) {// Start False Flag I NonNumberEntered = false; // Define whether a keystroke is a number from the top of the keyboard. If (E. ccode & lt; keys.D0 || e.KeyCode> Key.D9) {// Determine whether the keystroke has a number from the keypad or not (if E. ccode & lieutenant; keys no. Pad 0 || E. cacode> Keys. Numpad 9) {// Determine whether keystroke is a backspace or not. If (ekcode! = Keyback. Back) {nonNumberEntered = true; ErrorProvider1.SetError (Target IP, Field ValidationNumbersOnly); // A non-numerical keystroke was pressed. // Set the flag to correct and evaluate in KeyPress event}}} // If the shift key was pressed, this number is not if (Control.ModifierKeys == Keys.Shift) {nonNumberEntered = true; }} Private Zero TargetIP_KeyPress (Object Sender, KeyPressEventArgs E) {// Check for a flag being set in the KeyDown event if (nonNumberEntered == true) {// stop the character from being recorded in Control because it is non-numeric . E.Handled = True; } And {errorProvider1.Clear (); }}
gives you a general textbox control
- 9 alternate points or space
- Again, set the property to
990 \ .990 \ .990 \ .990and <0 required digits - \. Recommended to use the
maskedtextbox, but never (I can never change) used it myself Now I just tried it ... ok, forget what I said . I thought it could be a simple solution, but it is also an unusual solution.New, more complex, but far better suggestions and the way I usually do this.
-
Create a custom control with four text boxes, among them three labels with each dot.
-
Analyze the input.
- If the user enters the dot, a tab (controlled by the control), can be a location, the fourth digit.
- Discard whatever is not a number.
- If the digit is out of range from 0 to 255, then discard the digit.
- Change text to 0 if user deletes
-
Add an asset to the user control that returns the entered address.
-
Receivable can be writable and can add event handling.
-
Comments
Post a Comment