[英]How to check whether the input is not blank in Ant Input Task?
我有一個需要用戶輸入的ant腳本。 我想確保用戶輸入了正確的輸入類型,如果沒有輸入,請提示他們輸入正確的內容。
<input message="secure-input:" addproperty="the.password" >
</input>
我必須檢查輸入是否為空,然后我將提示他們重新輸入。
螞蟻輸入任務有可能嗎?
如果不滿足某些條件,大多數條件子句最多允許您使腳本失敗 。 我正在想象您正在收集用戶的一些輸入,因此如果用戶提供空密碼失敗可能不是最佳的可用性體驗,因為他將不得不重新輸入所有內容...
此外,僅測試一個空字符串似乎是一個較差的驗證,如果用戶提交一堆空格怎么辦?
我的建議(如下):
<target name="askPassword">
<local name="passwordToValidate"/>
<input message="secure-input:" addproperty="passwordToValidate"/>
<script language="javascript">
<![CDATA[
passwordToValidate = project.getProperty("passwordToValidate");
//You can add more validations here...
if(passwordToValidate.isEmpty()){
println("The password cannot be empty.");
project.executeTarget('askPassword');
}
]]>
</script>
<property name="the.password" value="${passwordToValidate}"/>
</target>
因此,亮點是:
我的2美分。
您可以使用條件任務檢查輸入是否為空,但也可以使用antcontrib添加if / else並顯示用戶適當的消息:
<if>
<not>
<length string="${the.password}" trim="true" when="greater" length="0" />
</not>
</if>
<then>
<echo>Your password is empty!</echo>
</then>
查看條件 -用於condition
任務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.