A Simple Example using RegExp:
<html>
<head>
<script language='javascript'>
function CheckThis(obj) {
var strRegExp = /^[0-9]*$/;
if(!strRegExp.test(obj.value))
obj.value = '';
}
</script>
</head>
<body>
<p>Insert your data number here:</p>
<input type='text' id='test' size='10' value='' onkeyup='CheckThis(this);'/>
</body>
</html>
I don't know if this can help you, i hope.
See more: http://evolt.org/regexp_in_javascript.
On Tue, Jun 9, 2009 at 12:02 AM, Newb Newb <[email protected]
> wrote:
>
> i use this code to validate the phone field.it should have only numbers.
> but it also accepts alphapets with numbers.it should not accept other
> than numkbers
> below is my code i use.
> errors.add(:phone_code, "*please enter valid phone number") unless
> self.phone_code =~/[0-9]/
>
> is there any fault in my regular expression ...
> any helps pls..
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---