Is the Clipboard Numeric?

DiverDan

Contributor
Joined
Jan 16, 2003
Messages
645
Location
Sacramento, CA
There are probably a ton of programmers that already do this, but since there is a concern in pasteing text in a textbox that only should accept numbers, here's how to check if the clipboard contains only a numeric value:

'Check Clipboard
Dim ClipboardText As String
Dim data As IDataObject = Clipboard.GetDataObject()

If (data.GetDataPresent(DataFormats.Text)) Then
ClipboardText = data.GetData(DataFormats.Text).ToString()
If IsNumeric(ClipboardText) Then
EnablePaste()
Else
DisablePaste()
End If
End If

Hope this helps someone.
Dan
 
Back
Top