title: programmatically validate a text field for mobile number
body: <p>in my application I need to validate mobile number text field in different forms. so I wish to write a
  function for this purpose.my needs are:</p>
  
  <p>text field accept <strong>only numbers(0-9)</strong>.
  error message will shown if any <strong>other characters are entered</strong>.
  does't allow space but <strong>allow ctrl+c,ctrl+v,ctrl+x ans back sapce</strong>.
  if <strong>ctrl+v(paste)</strong> is done it will check whether the string contains <strong>characters</strong>, if yes then <strong>display error message</strong>.
  does anyone can help me to write such a function in limited number of code?</p>
  
  <p>I had validated the following</p>
  
  <pre><code>Private Sub mob_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles stok.KeyPress
  If Asc(e.KeyChar) &lt; 48 Or Asc(e.KeyChar) &gt; 57 Then ' check whether the keypress is a number
  mob.ForeColor = Color.green 
  Else
  mob.ForeColor = Color.Red
  end if
  end sub
  
  Private Sub mob_LostFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles stok.KeyPress
  if mob.text="" then 'for check empty space
  end sub
  </code></pre>
  
  <p>but this is not what I need. I need all the process executed within a function</p>