如何驗證此代碼用戶輸入有效的IP地址我想在用戶輸入時顯示消息0.0.0.0
我可以使用請求範圍的bean並將其註冊爲inputtadress片段中的所有inputtext並檢查4個inputtext字段但我想知道有沒有其他的方法。驗證UI:片段
<ui:fragment >
<ui:include src="/misc/inputaddress.xhtml">
<ui:param name="id" value="ip" />
<ui:param name="value"
value="#{externalDataStorageAdder.storage.inputAddr}"
/>
</ui:include>
</ui:fragment>
這inputaddres
<div
style="border: 1px solid #c0c0c0; background-color: #ffffff; width: 162px;">
<h:inputText id="#{id}-field1"
style="width: 25px; border: 0px; text-align: center; background-color: white; background-image: url('');"
maxlength="3" value="#{value.field1}" onfocus="this.select();"
onkeyup="number_only(this);">
<f:validateLongRange minimum="0" maximum="255" />
</h:inputText> . <h:inputText id="#{id}-field2"
style="width: 25px; border: 0px; text-align: center; background-color: white; background-image: url('');"
maxlength="3" value="#{value.field2}" onfocus="this.select();"
onkeyup="number_only(this);">
<f:validateLongRange minimum="0" maximum="255" />
</h:inputText> . <h:inputText id="#{id}-field3"
style="width: 25px; border: 0px; text-align: center; background-color: white; background-image: url('');"
maxlength="3" value="#{value.field3}" onfocus="this.select();"
onkeyup="number_only(this);">
<f:validateLongRange minimum="0" maximum="255" />
</h:inputText> . <h:inputText id="#{id}-field4"
style="width: 25px; border: 0px; text-align: center; background-color: white; background-image: url('');"
maxlength="3" value="#{value.field4}" onfocus="this.select();"
onkeyup="number_only(this);">
<f:validateLongRange minimum="0" maximum="255" />
</h:inputText></div>