0

Please help me out I want to use the regular expression for IP address in that expression it should take only number not Alphabet text

suppose my IP Address is like that 111.111.1.111

When the user enter the IP address then starting it should take 3 number then dot like that goes on

i used these expression which help to stop writing Alphabet

if ("" != this.value.replace(/((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$/g, '')) {
          this.value = this.value.replace(/[^0-9\.]/g, '');
          } 
Atul Dhanuka
  • 1,453
  • 5
  • 20
  • 56
  • What problem are you experiencing with the code you've pasted? – David Hedlund Aug 12 '13 at 06:28
  • http://answers.oreilly.com/topic/318-how-to-match-ipv4-addresses-with-regular-expressions/ – huysentruitw Aug 12 '13 at 06:31
  • @DavidHedlund look what expression i used it help me to stop writing alphabet but when i type the number for ip address upto 3 digit it should number when i press 4 digit it should take dot not number but it is not happening – Atul Dhanuka Aug 12 '13 at 07:15

1 Answers1

3

Use this:

\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
Bhupendra Shukla
  • 3,814
  • 6
  • 39
  • 62
  • dude it is not working i need in fourth place only dot not a number or alphabet it is takin every thing even alphabet also – Atul Dhanuka Aug 12 '13 at 07:17